在公司使用docker多主機互聯時碰到了各類坑。搞清楚後才發現如此簡單,如下是根據實際經驗的總結.linux
Client: Version: 18.09.0 API version: 1.39 Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:48:22 2018 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.12) Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:19:08 2018 OS/Arch: linux/amd64 Experimental: false
# 初始化集羣 docker swarm init
docker swarm join-token worker To add a manager to this swarm, run the following command: docker swarm join --token SWMTKN-1-3jsci44ma4vq5lu62cw9qb2t91n1du0q8vpl2p0wzkcdk2smfi-bernmboygqmk6idgt5zc2l9z6 192.168.0.244:2377
docker swarm join --token SWMTKN-1-3jsci44ma4vq5lu62cw9qb2t91n1du0q8vpl2p0wzkcdk2smfi-bernmboygqmk6idgt5zc2l9z6 192.168.0.244:2377
docker network create -d overlay --attachable net
此時,在其它節點執行 docker network ls, 能夠看到該網絡已同步到全部節點,不一樣節點的主機指定該網絡建立的容器之間網絡已能互通。docker