分别创建两个目录用来存放配置文件和网页内容
[root@localhost ~]# mkdir -p /var/www/html [root@localhost ~]# mkdir -p /config上传下载好的html文件包
[root@localhost 38345]# cd /var/www/html/ [root@localhost html]# ls audio css images index.html js vendor安装nginx
[root@localhost ~]# yum -y install nginx //将配置文件复制到/config目录下 [root@localhost nginx]# pwd /etc/nginx [root@localhost nginx]# ls conf.d fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default default.d fastcgi_params koi-win nginx.conf scgi_params.default win-utf fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params [root@localhost nginx]# cp -r * /config/ [root@localhost nginx]# cd /config/ [root@localhost config]# ls conf.d fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default default.d fastcgi_params koi-win nginx.conf scgi_params.default win-utf fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params创建数据卷容器
[root@localhost ~]# docker run --name nginx1 -v /var/www/html/:/usr/share/nginx/html busybox [root@localhost ~]# docker ps -a ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e4f6f0030688 busybox "sh" 42 seconds ago Exited (0) 40 seconds ago nginx1 bb9283a9d50b centos:8 "/bin/bash" 11 hours ago Exited (255) 24 minutes ago
再创建一个数据卷存放配置文件
[root@localhost ~]# docker run --volumes-from nginx1 -v /config/:/etc/nginx --name nginx_conf busybox [root@localhost ~]# docker ps -a ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 182d7377105b busybox "sh" 14 seconds ago Exited (0) 13 seconds ago nginx_conf e4f6f0030688 busybox "sh" 3 minutes ago Exited (0) 3 minutes ago nginx1 bb9283a9d50b centos:8 "/bin/bash" 11 hours ago Exited (255) 27 minutes ago创建容器测试
查看nginx_conf这太主机是否有配置文件和网页内容
[root@localhost ~]# docker run -it --rm --volumes-from nginx_conf busybox / # ls /etc/nginx/ conf.d fastcgi_params mime.types scgi_params win-utf default.d fastcgi_params.default mime.types.default scgi_params.default fastcgi.conf koi-utf nginx.conf uwsgi_params fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default / # ls /usr/share/nginx/html/ audio css images index.html js vendor创建nginx镜像
[root@localhost ~]# docker run -itd --name web --volumes-from nginx_conf -P nginx Unable to find image 'nginx:latest' locally latest: Pulling from library/nginx e5ae68f74026: Pull complete 21e0df283cd6: Pull complete ed835de16acd: Pull complete 881ff011f1c9: Pull complete 77700c52c969: Pull complete 44be98c0fab6: Pull complete Digest: sha256:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603 Status: Downloaded newer image for nginx:latest 0495bd956b9aa3cb977fa27875c34cae8164cbac07f638ec2f1c40b57ad967c7 [root@localhost ~]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0495bd956b9a nginx "/docker-entrypoint.…" 9 minutes ago Up 9 minutes 0.0.0.0:35951->80/tcp, :::35951->80/tcp web [root@localhost ~]# docker exec -it web /bin/bash root@0495bd956b9a:/# ls /etc/nginx/ conf.d fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default default.d fastcgi_params koi-win nginx.conf scgi_params.default win-utf fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params root@0495bd956b9a:/# ls /usr/share/nginx/html/ audio css images index.html js vendor



