开始尝试使用docker-swarm之第一篇-hello world

尝试一下docker-swarm之hello world

hello world

https://docs.docker.com/engine/swarm/swarm-tutorial/create-swarm/

初始化

1
2
3
4
docker swarm init

# response following
Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (10.0.2.15 on enp0s3 and 192.0.0.30 on enp0s8) - specify one with --advertise-addr

由于有两个ip,那么,需要加上--advertise-addr

1
2
3
4
5
6
7
8
9
10
11
12
13
14

docker swarm init --advertise-addr 192.0.0.30

# response following

此设备的hostname为swarmmanger

Swarm initialized: current node (xgjnkzvysal5fv7ugm1t5d7zr) is now a manager.

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

docker swarm join --token SWMTKN-1-0mzmp1o6vufmqmpo8rvyrg2kzvlakj94gweg6drqunzhmvvmxr-6i80acmunj32z9xqw1jbbmeln 192.0.0.30:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

此时,初始化节点成功。

根据提示,当前为manager节点,如果后续要加一个work节点

1
docker swarm join --token SWMTKN-1-0mzmp1o6vufmqmpo8rvyrg2kzvlakj94gweg6drqunzhmvvmxr-6i80acmunj32z9xqw1jbbmeln 192.0.0.30:2377

如要添加一个管理员,需执行docker swarm join-token manager打印出相关信息,再打印出的信息加入

hello world

按基本法,运行一个hello world就叫学会了

https://docs.docker.com/engine/swarm/swarm-tutorial/deploy-service/

1
2
3
4
5
6
7
docker service create --replicas 1 --name helloworld alpine ping docker.com

# response following
guwguxcvb3pnagtmy645xwd42
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged

查看当前服务

1
2
3
4
5
6
docker service ls

#response following
ID NAME MODE REPLICAS IMAGE PORTS
v7dfc1ktvm4o helloworld replicated 1/1 alpine:latest
guwguxcvb3pn helloworld1 replicated 1/1 alpine:latest

直接用docker ps 也可以看

1
2
3
4
5
docker ps
#response following
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac9bfeb74374 alpine:latest "ping docker.com" 3 minutes ago Up 3 minutes helloworld.1.27sb11llxgtesl88dxc4gqu72
ff50e95a964d alpine:latest "ping baidu.com" 3 minutes ago Up 3 minutes helloworld1.1.wgphxyqcc8xrrdv2zco8fc1lt
0%