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、浏览器访问

 

转载于:https://www.cnblogs.com/xiangsikai/p/9939421.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值