Docker Swarm

Docker Swarm环境部署

服务器环境信息
主机名称主机IP
docker-010.10.10.30
docker-110.10.10.31
docker-210.10.10.32
初始化docker swarm
# 在docker-0服务器上执行
$ docker swarm init --advertise-addr 10.10.10.30  # 在有多块网卡时指定绑定ip
Swarm initialized: current node (uj64m1ay4ftshvlpatzcklhsa) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join --token SWMTKN-1-0tdwzqsm8scntd9pj32x7py3yglp7j921gaswjg0td2qxs2b90-5ng50j4e3fz6rfyigyamtw6q0 10.10.10.30:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
加入docker swarm集群
# 在docker-1和docker-2服务器上执行
$ docker swarm join --token SWMTKN-1-0tdwzqsm8scntd9pj32x7py3yglp7j921gaswjg0td2qxs2b90-5ng50j4e3fz6rfyigyamtw6q0 10.10.10.30:2377
This node joined a swarm as a worker.
docker swarm高可用方案
# 将docker-1及docker-2提升为备用manager节点
# 在docker-0上执行命令
$ docker node promote docker-1
Node docker-1 promoted to a manager in the swarm.
# 检查node状态
$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
uj64m1ay4ftshvlpatzcklhsa *   docker-0            Ready               Active              Leader              18.09.4
z0kqnpnsylcxw0i0na05kb0b3     docker-1            Ready               Active              Reachable           18.09.4
nlmnwivdsap75qx8798foom0u     docker-2            Ready               Active              Reachable           18.09.4
创建一个测试服务
$ docker service create --name test1 alpine ping www.baidu.com
开通一个nginx服务
$ docker service create --name nginx nginx
# 开通nginx暴露的端口
$ docker service update --publish-add 80:80 nginx
# 开启nginx高可用(增加nginx运行节点)
$ docker service scale nginx=3
创建docker network网络
$ docker network create -d overlay nginx-overlay
# 检查网络情况
$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
740da093ed9b        bridge              bridge              local
76ec1a041199        docker_gwbridge     bridge              local
65ba5fffa724        host                host                local
l9luemje94ft        ingress             overlay             swarm
w90la9zdlxyg        nginx-overlay       overlay             swarm
8bbec75fc40d        none                null                local
将docker加入网络
# 停止nginx,test容器运行
$ docker service rm nginx test
# 启动nginx容器
$ docker service create --network nginx-overlay --name nginx -p 80:80 -p 443:443 nginx
# 启动客户端容器
$ docker service create --network nginx-overlay --name client alpine ping www.baidu.com
# 验证容器间访问
# 进入客户端容器访问nginx
$ docker exec -it 322a276ac1c3 sh  (可以通过docker ps 命令获取client的CONTAINER ID)
/ # ping nginx
PING nginx (10.0.0.2): 56 data bytes
64 bytes from 10.0.0.2: seq=0 ttl=64 time=0.261 ms
64 bytes from 10.0.0.2: seq=1 ttl=64 time=0.162 ms
创建dnsrr服务的nginx
# 只适用于容器间访问
$ docker service create --network nginx-overlay --name nginx-1 --endpoint-mode dnsrr nginx
docker分组
$ docker stack deploy -c filename.yml test
$ cat filename.yml
version: "3.4"
services:
  alpine:
    image: alpine
    command:
      - "ping"
      - "www.baidu.com"
    networks:
      - "nginx-overlay"
    deploy:
      endpoint_mode: dnsrr
      replicas: 2
      restart_policy:
        condition: on-failure
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
    depends_on:
      - nginx
  nginx:
    image: nginx
    networks:
      - "nginx-overlay"
    ports:
      - "80:80"
networks:
  nginx-overlay:
    external: true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IA有梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值