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

2021/12/9 7:23:56

本文主要是介绍使用不同的配置文件与网页文件部署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



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



这篇关于使用不同的配置文件与网页文件部署nginx容器的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程