docker创建nginx容器

创建nginx镜像(提供配置文件和网页文件)

#拉取镜像
[root@localhost ~]# docker pull neawalke/nginx:v2.0
v2.0: Pulling from neawalke/nginx
a1d0c7532777: Already exists 
85731d77a16c: Pull complete 
716b1ea9bb1a: Pull complete 
Digest: sha256:fbdb7ed8e30110b5d3e5ab90c968bd1c148adec36fa70afcbc468bdc0ef101ad
Status: Downloaded newer image for neawalke/nginx:v2.0
docker.io/neawalke/nginx:v2.0

#将网页文件放在/var/www/html下
[root@localhost ~]# ls /var/www/html/
images  index.html  scripts  sound

#创建一个配置nginx网页的容器
[root@localhost ~]# docker run -it --name html -v /var/www/html:/usr/local/nginx/html neawalke/nginx:v2.0 

[root@localhost ~]# docker exec -it html /bin/bash
[root@74ab2e5f4111 /]# ls /usr/local/nginx/html/
images	index.html  scripts  sound

#将nginx的配置文件拷贝到本机上
[root@localhost ~]# docker container cp -a html:/usr/local/nginx/conf/ /config/
[root@localhost ~]# ls /config/
conf
[root@localhost ~]# ls /config/conf/
fastcgi.conf          fastcgi_params.default  mime.types          nginx.conf.default   uwsgi_params
fastcgi.conf.default  koi-utf                 mime.types.default  scgi_params          uwsgi_params.default
fastcgi_params        koi-win                 nginx.conf          scgi_params.default  win-utf

#创建一个nginx配置文件的容器
[root@localhost ~]# docker run -d --name nginx_conf --volumes-from html -v /config/conf:/usr/local/nginx/conf neawalke/nginx:v2.0

[root@localhost ~]# docker run -it --name web -p 80:80 --volumes-from nginx_conf neawalke/nginx:v2.0 

在这里插入图片描述
修改配置文件

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
images  index.html  scripts  sound
[root@localhost html]# mkdir game
[root@localhost html]# mv images index.html scripts sound game/
[root@localhost html]# ls
game
[root@localhost html]# mkdir test
[root@localhost html]# echo "hello word" > test/index.html


[root@localhost html]# cd /config/conf/
[root@localhost conf]# vim nginx.conf

    server {
        listen      80;
        server_name test.example.com;

        location / {
            root        /usr/local/nginx/html/test;
            index       index.html;
        }
    }

    server {
        listen       8080;
        server_name  game.example.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/nginx/html/game;
            index  index.html index.htm;
        }


[root@localhost conf]# docker run -it --name web -p 80:80 -p 8080:8080 --volumes-from nginx_conf neawalke/nginx:v2.0 

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值