创建项目目录,并设置用户与用户组。(tp5为例)
image.png
创建nginx和php的dockerfile
nginx
FROM nginx
//设置docker里面nginx用户的用户id
RUN usermod -u 1001 nginx
php
FROM php:7.1.0-fpm
//设置docker里面www-data用户的用户id
RUN usermod -u 1001 www-data
RUN apt-get update
RUN apt-get install vim
构建镜像
docker build -t nginx:test .
启动容器
nginx(设置.bashrc的目的是进入docker里面可以使用ll查看文件权限)
docker run --name my-nginx -p 80:80 -d -v /home/www:/usr/share/nginx/html -v /home/nginx/conf/conf.d:/etc/nginx/conf.d -v /home/nginx/.bashrc:/root/.bashrc --link
my-php:php nginx:my
php
docker run --name my-php -v /home/www/tp5:/var/www/html -v /home/nginx/.bashrc:/root/.bashrc -p 9000:9000 -d php:my
nginx的配置文件
server {
listen 80;
server_name tp5.examlpe.com;
root /usr/share/nginx/html/tp5/public/;
set $root /usr/share/nginx/html/tp5/public/;
location ~ .*\.(mp4)$
{
client_body_buffer_size 2048m;
client_max_body_size 120m;
root $root;
}
location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root $root;
}
location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /var/www/html/public/;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/public/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/var/www/html/:/tmp/:/proc/";
include fastcgi_params;
}
}
.bashrc文件
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "`dircolors`"
# alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'