Docker Swarm 配置文件存儲

Docker Swarm 配置文件存儲html

  • config:宿主級容器服務配置文件單獨保存到docker中存儲調用。

環境:nginx

  • 系統:Centos 7.4 x64
  • 應用版本:Docker 18.09.0
  • 管理節點:192.168.1.79
  • 工做節點:192.168.1.78
  • 工做節點:192.168.1.77

一、管理節點:宿主級當前目錄建立Nginx配置文件docker

vim site.confvim

server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}

二、管理節點:將site.conf保存到docker配置存儲中瀏覽器

#  docker config create docker 配置文件名 本地配置文件
docker config create site.conf site.conf

三、管理節點:建立一個Nginx並應用這個配置ide

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 
命令解析

四、工做節點:切換到容器查看配置文件spa

# 切換到容器內
# cat /etc/nginx/conf.d/site.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}

五、瀏覽器訪問code

相關文章
相關標籤/搜索