Docker Swarm 配置文件存儲
- config:宿主級容器服務配置文件單獨保存到docker中存儲調用。
環境:
- 系統:Centos 7.4 x64
- 應用版本:Docker 18.09.0
- 管理節點:192.168.1.79
- 工作節點:192.168.1.78
- 工作節點:192.168.1.77
1、管理節點:宿主級當前目錄創建Nginx配置文件
vim site.conf
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } }
2、管理節點:將site.conf保存到docker配置存儲中
# docker config create docker 配置文件名 本地配置文件 docker config create site.conf site.conf
3、管理節點:創建一個Nginx並應用這個配置
docker service create \ --name nginx \ --config source=site.conf,target=/etc/nginx/conf.d/site.conf \ --publish 8080:80 \ nginx:latest

# 創建服務 docker service create \ # 服務名 --name nginx \ #添加配置文件,source=docker配置文件,target=配置文件路徑 --config source=site.conf,target=/etc/nginx/conf.d/site.conf \ # 暴露端口 --publish 8080:80 \ # 使用鏡像 nginx:latest
4、工作節點:切換到容器查看配置文件
# 切換到容器內 # cat /etc/nginx/conf.d/site.conf server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } }
5、瀏覽器訪問