栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

使用不同的配置文件与网页文件部署nginx容器

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用不同的配置文件与网页文件部署nginx容器

使用不同的配置文件与网页文件部署nginx容器,这样部署一个容器就能访问不同的网站。

//拉一个之前源码部署nginx的镜像
[root@localhost ~]# docker pull luohengjie/nginx:v1.20.1
v1.20.1: Pulling from luohengjie/nginx
a1d0c7532777: Already exists 
e2bd604551a4: Pulling fs layer 
v1.20.1: Pulling from luohengjie/nginx
a1d0c7532777: Already exists 
e2bd604551a4: Pull complete 
Digest: sha256:e072fd0e2126c8dc70afb349eaf4ad42307f0583ddedf8c458390142bfa13964
Status: Downloaded newer image for luohengjie/nginx:v1.20.1
docker.io/luohengjie/nginx:v1.20.1

[root@localhost ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED        SIZE
httpd              v1.0      3471d3329f64   31 hours ago   721MB
luohengjie/nginx   v1.20.1   57f37b97be37   5 days ago     550MB
nginx              latest    f652ca386ed1   5 days ago     141MB
centos             latest    5d0da3dc9764   2 months ago   231MB
[root@localhost ~]# docker run -d --name nginx luohengjie/nginx:v1.20.1
2114830a23d68b5ca03342af8fea288ba68c4fa9f82ea05b76be95a370cae602
[root@localhost ~]# docker ps -a
ConTAINER ID   IMAGE                      COMMAND                  CREATED         STATUS         PORTS     NAMES
2114830a23d6   luohengjie/nginx:v1.20.1   "/usr/local/nginx/sb…"   4 seconds ago   Up 3 seconds             nginx

//创建一个目录来放提出来的文件
[root@localhost ~]# mkdir config
[root@localhost ~]# docker cp  nginx:/usr/local/nginx/conf config/
[root@localhost ~]# docker cp  nginx:/usr/local/nginx/html config/
[root@localhost ~]# ls config/
conf  html

[root@localhost ~]# mkdir config/html/test
[root@localhost ~]# echo "hello world" > html/test/index.html
-bash: html/test/index.html: 没有那个文件或目录
[root@localhost ~]# echo "hello world" > config/html/test/index.html
[root@localhost ~]# ls config/html/test/
index.html


[root@localhost ~]# vim config/conf/nginx.conf
//添加以下行
.....略
 84     server {
 85         listen       8080;
 86         server_name test.example.com;
 87 
 88         location / {
 89             root   html/test;
 90             index  index.html index.htm;
 91            }
 92     }
 93 
 94 
.....略

启动容器

//映射端口和本地文件
[root@localhost ~]# docker run -itd --name web -v /root/config/html:/usr/local/nginx/html  -v /root/config/conf:/usr/local/nginx/conf -p 8080:8080 -p 80:80 luohengjie/nginx:v1.20.1 
e18b390b84e9faef38317ceaf0245db2c475f8613d137a3d485ff192286371bf



以后可以通过直接修改本地文件来创建容器达到快速部署的目的

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/642444.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号