Docker存储卷实战-Nginx

本文详细介绍了如何在Docker中创建Nginx容器,并通过存储卷映射配置文件和网站内容。操作包括更换网站页面、制作多个访问页面以及使用restart命令重启容器,确保Nginx服务的稳定运行。
摘要由CSDN通过智能技术生成

创建Nginx容器,同时提供配置文件和网页文件

映射配置文件和网站

// 真机网站存放位置
[root@localhost ~]# ls /var/www/html/
articles.xls  game.html  images  index.html  js  style

// 拉取一个nginx镜像
[root@localhost ~]# docker pull nginx

[root@localhost ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED        SIZE
nginx              latest    f652ca386ed1   4 days ago     141MB
busybox            latest    d23834f29b38   7 days ago     1.24MB
centos             latest    5d0da3dc9764   2 months ago   231MB

// 制作一个网站映射
[root@localhost ~]# docker run -it --name html -v /var/www/html:/usr/share/nginx/html busybox
/ # exit
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS                     PORTS     NAMES
353751ed8264   busybox   "sh"      5 seconds ago   Exited (0) 2 seconds ago             html

// 使用一个测试容器登入进去查看映射情况
[root@localhost ~]# docker run -it --volumes-from html busybox
/ # ls /usr/share/nginx/html/	// 网站映射成功
articles.xls  images        js
game.html     index.html    style

// 把测试的容器删除
/ # exit
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS                     PORTS     NAMES
64ff86f2f505   busybox   "sh"      2 minutes ago   Exited (0) 3 seconds ago             xenodochial_brattain
353751ed8264   busybox   "sh"      2 minutes ago   Exited (0) 2 minutes ago             html
[root@localhost ~]# docker rm -f 64ff86f2f505
64ff86f2f505

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS                     PORTS     NAMES
353751ed8264   busybox   "sh"      4 minutes ago   Exited (0) 4 minutes ago             html

// 创建配置文件存放目录
[root@localhost ~]# mkdir /config
[root@localhost ~]# ls /config/

// 先用yum安装一个nginx
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install nginx

// 默认配置文件存放位置
[root@localhost ~]# 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

// 复制配置文件到config目录下
[root@localhost ~]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值