你在master上创建容器的根本原因,我们应该在swarm agent上创建容器。默认情况下,我们不能在 swarm master 上创建容器。
一旦我们满足于 swarm master 并运行docker info,信息如下:
root@swarm-master-784816DA-0:~# docker info
Containers: 2
Running: 2
Paused: 0
Stopped: 0
Images: 2
Server Version: 17.06.0-ce
Storage Driver: overlay
Backing Filesystem: extfs
Supports d_type: 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: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
apparmor
Kernel Version: 3.19.0-65-generic
Operating System: Ubuntu 14.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 6.805GiB
Name: swarm-master-784816DA-0
ID: IKDF:RSRH:CXT2:M6ER:KI4R:DYAR:2CZH:FFQX:MCRT:4NZB:CBS4:LNRK
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
Live Restore Enabled: false
WARNING: No swap limit support
然后我们访问 docker swarm 集群,将 DOCKER_HOST 环境变量设置为您为隧道配置的本地端口,使用此命令 export DOCKER_HOST=:2375 和 docker info:
root@swarm-master-784816DA-0:~# export DOCKER_HOST=:2375
root@swarm-master-784816DA-0:~# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 1
swarm-agent-784816DA000001: 10.0.0.5:2375
└ Status: Healthy
└ Containers: 0
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 7.145 GiB
└ Labels: executiondriver=<not supported>, kernelversion=3.19.0-65-generic, operatingsystem=Ubuntu 14.04.4 LTS, storagedriver=overlay
└ Error: (none)
└ UpdatedAt: 2017-07-03T01:57:18Z
Plugins:
Volume:
Network:
Log:
Swarm:
NodeID:
Is Manager: false
Node Address:
Kernel Version: 3.19.0-65-generic
Operating System: linux
Architecture: amd64
CPUs: 2
Total Memory: 7.145GiB
Name: 2076070ddfd8
Docker Root Dir:
Debug Mode (client): false
Debug Mode (server): false
Experimental: false
Live Restore Enabled: false
WARNING: No kernel memory limit support
然后我们运行docker ps来获取信息:
root@swarm-master-784816DA-0:~# docker run -d -p 80:80 yeasy/simple-web
0226e9ab3cadf20701f64c02f1f4a42f5fd57fd297722f268db47db1b124ab5c
root@swarm-master-784816DA-0:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0226e9ab3cad yeasy/simple-web "/bin/sh -c 'pytho..." 6 seconds ago Up 5 seconds 10.0.0.5:80->80/tcp swarm-agent-784816DA000001/stupefied_snyder
那么我们就可以使用swarm-agent-lb负载均衡器的公共IP地址或DNS来访问网站了。
更多关于设置环境的信息,请参考link。