创建nginx容器
docker build -t nginx:v1 -f Dockerfile-nginx .
创建volume
docker volume create nginx_html
docker volume create nginx_conf
docker volume create nginx_log
查看volume
docker volume ls
docker volume inspect nginx_html
docker volume inspect nginx_conf
启动ngixn容器
docker run -d --name nginx02 --mount src=nginx_html,dst=/usr/local/nginx/html --mount src=nginx_conf,dst=/usr/local/nginx/conf --mount src=nginx_log,dst=/usr/local/nginx/log -p 80:80 nginx:v1
进入容器
docker exec -it nginx02 /bin/bash
Dockerfile-nginx
FROM centos:7
MAINTAINER kahn
RUN yum install -y gcc gcc-c++ make \
openssl-devel pcre-devel gd-devel \
iproute net-tools telnet wget curl && \
yum clean all && \
rm -rf /var/cache/yum/*
RUN wget http://nginx.org/download/nginx-1.15.5.tar.gz && \
tar zxf nginx-1.15.5.tar.gz && \
cd nginx-1.15.5 &&\
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_stub_status_module && \
make -j 4 && make install && \
rm -rf /usr/local/nginx/html/* && \
echo "ok" >> /usr/local/nginx/html/status.html && \
cd / && rm -rf nginx-1.12.2* && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ENV PATH $PATH:/usr/local/nginx/sbin
#COPY nginx.conf /usr/local/nginx/conf/nginx.conf
WORKDIR /usr/local/nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]