Docker 17.06中的服务无法在群集模式下随机工作

运行服务命令:

docker service create -d \ -p 8080:8080 \ --mount type=bind,source=/etc/localtime,target=/etc/localtime \ --mount type=bind,source=/etc/timezone,target=/etc/timezone \ --mount type=bind,source=/home/test/docker/manager,target=/root \ --network test-network \ --workdir /root \ --name test-manager \ --replicas 2 \ --limit-cpu 2 \ --limit-memory 4G \ java:8 java -Dspring.profiles.active=$PROFILE -jar -Xms512m -Xmx4096m /root/target/test-manager.jar 

服务启动后,我用curl 192.168.2.48:8080/infotesting了服务,有50%的请求没有工作。 用docker exec -it xxx bashinput容器,用curl 10.0.1.6:8080/infocurl 10.0.1.7:8080/info ,发现所有结果都OK。 但是,如果我重新启动上述服务几次,有时候,所有的请求都完全工作。

networking检查

 nc -vuz 192.168.2.48 4789 nc -vz 192.168.2.48 2377 nc -vuz 192.168.2.48 7946 nc -vz 192.168.2.48 7946 

一切都成功了。

docker info结果:

 Containers: 4 Running: 3 Paused: 0 Stopped: 1 Images: 25 Server Version: 17.06.0-ce Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 102 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: tdc32kn0n6bwcz32ljvprcmq0 Is Manager: true ClusterID: hdyakushxu1c6rsk2cml7b0l3 Managers: 2 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 Root Rotation In Progress: false Node Address: 192.168.2.47 Manager Addresses: 192.168.2.47:2377 192.168.2.48:2377 Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4 init version: 949e6fa Security Options: apparmor seccomp Profile: default Kernel Version: 4.4.0-92-generic Operating System: Ubuntu 16.04.3 LTS OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 7.78GiB Name: ubuntu-qgsp01 ID: RP4U:E3PW:AU5R:BLD2:2QDL:DA25:GY2P:YV67:IR2F:GEBZ:XVX3:XC72 Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://20agqwyc.mirror.aliyuncs.com/ Live Restore Enabled: false 

我怀疑由networking负载平衡或贵宾造成的问题,一个节点无法到达,所以服务被吊死。 但是如果我在一个容器中ping另一个,我发现networking正在工作。 我感到困惑。

这个问题一直困扰着我很久,希望有人能帮助我。