1. 程式人生 > >Docker Swarm 配置檔案儲存

Docker Swarm 配置檔案儲存

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、瀏覽器訪問