以更方便的方式配置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
网友评论