当前位置:   article > 正文

docker使用数据卷创建nginx容器_创建带数据卷、端口映射的nginx_1容器

创建带数据卷、端口映射的nginx_1容器

docker使用数据卷创建nginx容器

//创建存放网站的和配置文件的目录
[root@docker ~]# mkdir -p /var/www/html
[root@docker ~]# mkdir /config

#配置文件可yum安装Nginx,再copy到/config目录
[root@docker ~]# ls /var/www/html/
index.html
[root@docker ~]# ls /config/
conf.d                  mime.types.default
default.d               nginx.conf
fastcgi.conf            nginx.conf.default
fastcgi.conf.default    scgi_params
fastcgi_params          scgi_params.default
fastcgi_params.default  uwsgi_params
koi-utf                 uwsgi_params.default
koi-win                 win-utf
mime.types


//创建数据卷容器
[root@docker nginx]# docker run --name html -v /var/www/html/:/usr/share/nginx/html busybox		#-v:将宿主机目录映射到容器目录
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
3cb635b06aa2: Pull complete 
Digest: sha256:70eb6b39a8db2834d27b221899aa6c30a4d9648c804cf0586d8d6ea202327fe7
Status: Downloaded newer image for busybox:latest
[root@docker nginx]# docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED             STATUS                      PORTS     NAMES
109a44ecb413   busybox        "sh"                     5 minutes ago       Exited (0) 5 minutes ago              html

//测试
[root@docker nginx]# docker run -it --rm --volumes-from html busybox
/ # ls /usr/share/nginx/html/
index.html


[root@docker ~]# docker run --volumes-from html -v /config/:/etc/nginx --name nginx_conf busybox
[root@docker ~]# docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED             STATUS                         PORTS     NAMES
3e99ef74777e   busybox        "sh"                     14 seconds ago      Exited (0) 13 seconds ago                nginx_conf
109a44ecb413   busybox        "sh"                     8 minutes ago       Exited (0) 8 minutes ago                 html

//测试
[root@docker ~]# docker run -it --rm --volumes-from nginx_conf busybox
/ # ls /usr/share/nginx/html/
html-editor-master  index.html
/ # ls /etc/nginx/
conf.d                  mime.types.default
default.d               nginx.conf
fastcgi.conf            nginx.conf.default
fastcgi.conf.default    scgi_params
fastcgi_params          scgi_params.default
fastcgi_params.default  uwsgi_params
koi-utf                 uwsgi_params.default
koi-win                 win-utf
mime.types
/ # exit


//基于Nginx镜像创建数据卷容器
[root@docker ~]# docker run -d --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
ca2325c6127c17db7d0459ac09355db20ddab0281e80a1c8358bd316a4617221

[root@docker ~]# docker ps 
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                     NAMES
ca2325c6127c   nginx     "/docker-entrypoint.…"   25 seconds ago   Up 23 seconds   0.0.0.0:49153->80/tcp, :::49153->80/tcp   web

[root@docker ~]# docker exec -it web /bin/bash
root@ca2325c6127c:/# ls /etc/nginx/
conf.d                  mime.types.default
default.d               nginx.conf
fastcgi.conf            nginx.conf.default
fastcgi.conf.default    scgi_params
fastcgi_params          scgi_params.default
fastcgi_params.default  uwsgi_params
koi-utf                 uwsgi_params.default
koi-win                 win-utf
mime.types
root@ca2325c6127c:/# ls /usr/share/nginx/html/
index.html
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90

访问
请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/196113
推荐阅读
相关标签
  

闽ICP备14008679号