Docker容器

docker数据卷部署nginx容器

本文主要是介绍docker数据卷部署nginx容器,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

docker数据卷部署nginx容器

[root@Aimmi ~]# mkdir -p /config
[root@Aimmi ~]# cd /var/www/html/
[root@Aimmi html]# ls
index.html  index_files

将配置文件复制到/config目录下
[root@Aimmi ~]# yum -y install nginx
[root@Aimmi ~]# cd /etc/nginx/
[root@Aimmi 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@Aimmi nginx]# cp -r * /config/
[root@Aimmi nginx]# cd /config/
[root@Aimmi 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@Aimmi ~]# docker run --name nginx1 -v /var/www/html/:/usr/share/nginx/html busybox
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
3cb635b06aa2: Pull complete 
Digest: sha256:b5cfd4befc119a590ca1a81d6bb0fa1fb19f1fbebd0397f25fae164abe1e8a6a
Status: Downloaded newer image for busybox:latest

创建一个数据卷存放配置文件
[root@Aimmi ~]# docker run --volumes-from nginx1 -v /config/:/etc/nginx --name nginx_conf  busybox

创建nginx镜像
[root@Aimmi ~]# 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
e2dea3b5fb627b4df1a1516483b8ca2808d3e7c771106fd071c9b4b544aa94bb
[root@Aimmi ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                     NAMES
e2dea3b5fb62   nginx     "/docker-entrypoint.…"   8 seconds ago   Up 7 seconds   0.0.0.0:49153->80/tcp, :::49153->80/tcp   web

[root@Aimmi ~]# docker exec -it web /bin/bash
root@e2dea3b5fb62:/# 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@e2dea3b5fb62:/# ls /usr/share/nginx/html/
index.html  index_files


 

这篇关于docker数据卷部署nginx容器的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!