如何正确连接docker中的worker节点?

时间:2018-05-23 08:24:43

标签: docker docker-compose docker-swarm

我将docker设置为1个Manager和1个Worker。两个节点都是同一网络中的独立机器。 在管理器节点中初始化的docker swarm,并使用管理器节点生成的docker swarm join-token worker代码将另一台PC连接到swarm。

docker info经理节点

Containers: 16
 Running: 5
 Paused: 0
 Stopped: 11
Images: 303
Server Version: 18.03.1-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 572
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: v5out80i284bavbkhrny82non
 Is Manager: true
 ClusterID: 2h6jhemo4ch03zzk9dm8hkn97
 Managers: 1
 Nodes: 2
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
  Force Rotate: 0
 Autolock Managers: false
 Root Rotation In Progress: false
 Node Address: 10.0.0.1
 Manager Addresses:
  10.0.0.1:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.13.0-37-generic
Operating System: KDE neon Developer Edition
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.691GiB
Name: wannamit
ID: KR2B:Q2E6:GAPR:HY6X:PYZQ:KUMU:DXCE:7YKI:E5MM:RRHO:BBWG:GM6S
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: amithp
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

docker info工作人员节点

Containers: 4
 Running: 4
 Paused: 0
 Stopped: 0
Images: 4
Server Version: 18.03.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
 NodeID: vvusfvjpenc9ymsotj4bcs25c
 Is Manager: false
 Node Address: 192.168.86.38
 Manager Addresses:
  10.0.0.1:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-22-generic
Operating System: Ubuntu 18.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.093GiB
Name: ubuntu
ID: SKCQ:JZGO:VUHX:HZN5:JD4H:4KPM:5RXK:DWG2:A7E6:WU4T:VQ5N:YHQB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

使用5次复制部署Simple。

version: "3.2"
services:
  webapp:
    image: amithp/pyapp:latest
    deploy:
      replicas: 5
      restart_policy:
        condition: on-failure
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
    ports:
      - "28888:28888"
    networks:
      - frontend-network

  redis:
    image: redis
    command: redis-server --appendonly yes
    deploy:
      restart_policy:
        condition: on-failure
    networks:
      - frontend-network

networks:
  frontend-network:
    external:
      name: frontend-network

部署成功。大多数情况下,2部署在Manager节点,另外3部署,Redis部署在工作节点上。 docker图像是一个烧瓶应用程序,显示总视图计数和来自应用程序的原始IP。

  

你好世界!

     

主机名:351d83b03555

     

HostIP:10.0.0.28

     

访问:无法连接到Redis,禁用计数器

现在,如果我从经理节点访问localhost:2888。它无法连接到redis,只能在2个不同的IP上循环。我交叉检查了那些IP,它们来自经理节点。此外,我在工作节点中识别了容器的IP并尝试从管理器节点的容器中ping,响应无法连接到主机(没有ping回复)。

我做错了什么或者我错过了什么?

0 个答案:

没有答案