优化:nginx容器的配置

以更方便的方式配置nginx容器:

过程:

①将一个容器卷挂载到nginx容器的配置文件目录
②查看这个容器卷在宿主机磁盘上的位置
③所看到的位置就是nginx容器配置文件目录

容器组配置文件:

[root@node1 docker-compose]# cat docker-compose.yml 
version: "2"
services:
  nginx:
    image: nginx:latest
    ports:
     - "8181:80"
    volumes:
     - nginx-conf:/etc/nginx/
volumes:
  nginx-conf:
    driver: ${volume_driver}(这个是空的字符串-_-,默认为local)

启动容器组:

[root@node1 docker-compose]# docker-compose up     
WARNING: The volume_driver variable is not set. Defaulting to a blank string.
Creating volume "dockercompose_nginx-conf" with default driver
Creating dockercompose_nginx_1
Attaching to dockercompose_nginx_1

查看容器卷位置:

[root@node1 docker-compose]# docker volume ls
DRIVER              VOLUME NAME
local               647231651fc20c125a99a435afdf6756b26493fbaa688d34456e37da416a6660
local               dockercompose_nginx-conf
[root@node1 docker-compose]# docker volume inspect dockercompose_nginx-conf
[
    {
        "Name": "dockercompose_nginx-conf",
        "Driver": "local",
        "Mountpoint": "/var/lib/docker/volumes/dockercompose_nginx-conf/_data",
        "Labels": null,
        "Scope": "local"
    }
]

可以在这里直接修改nginx的配置文件:

[root@node1 docker-compose]# ll /var/lib/docker/volumes/dockercompose_nginx-conf/_data
total 36
drwxr-xr-x 2 root root   25 Dec 26  2017 conf.d
-rw-r--r-- 1 root root 1007 Dec 26  2017 fastcgi_params
-rw-r--r-- 1 root root 2837 Dec 26  2017 koi-utf
-rw-r--r-- 1 root root 2223 Dec 26  2017 koi-win
-rw-r--r-- 1 root root 5170 Dec 26  2017 mime.types
lrwxrwxrwx 1 root root   22 Dec 26  2017 modules -> /usr/lib/nginx/modules(此处闪烁,链接断开!?)
-rw-r--r-- 1 root root  643 Dec 26  2017 nginx.conf
-rw-r--r-- 1 root root  636 Dec 26  2017 scgi_params
-rw-r--r-- 1 root root  664 Dec 26  2017 uwsgi_params
-rw-r--r-- 1 root root 3610 Dec 26  2017 win-utf

重启容器组生效配置:
另外开一个终端

[root@node1 docker-compose]# docker-compose restart

附driver值的属性:

 - variable: "volume_driver"
      description: "Volume driver to associate with this service"
      label: "Volume Driver"
      required: true
      default: "local"
      type: enum
      options: # List of options if using type of `enum`
        #(driver值列表)
        - local
        - rancher-nfs
        - rancher-efs
        - rancher-ebs
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小之食人魔

学习技术是为了早点下班!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值