第一步,下载nginx的镜像
docker pull nginx
第二步,部分修改
#This is a nginx dockerfile
#Source image
FROM nginx
#Author
MAINTAINER LeonLong from dockerpool.conf [email protected]
#mount point
VOLUME /opt/nginx/conf
VOLUME /var/log/nginx
VOLUME /opt/nginx/www
#Run instructions
RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
CMDnginx -g "daemon off;"
注意:CMD指令中都是以非daemon模式启动的进程,如果不关闭daemon模式,通过docker ps就可以看到,容器的启动只会被运行一次就结束了
第三步,构建自己的镜像
cd /opt/docker/dockerfiles/nginx/ ;docker build -t nginx:private .
第四步,启动
创建相关目录,并启动docker容器nginx
docker run -it -p 80:80 -p 443:443 -v /opt/docker/mounts/nginx/log:/var/log/nginx -v /opt/docker/mounts/nginx/conf:/opt/nginx/conf -v /opt/docker/mounts/nginx/www:/opt/nginx/www --name nginxtest nginx:private