Docker swarm

[root@instance-1 ~]# docker swarm
Usage: docker swarm COMMAND
Manage Docker Swarm
Options:
–help Print usage
Commands:
init Initialize a swarm
join Join a swarm as a node and/or manager
join-token Manage join tokens
update Update the swarm
leave Leave the swarm (workers only)
Run ‘docker swarm COMMAND –help’ for more information on a command.

[root@instance-1 ~]# docker swarm init –advertise-addr 172.18.0.1
Swarm initialized: current node (e2luo3xtlpqdwvko6p5tvn38j) is now a manager.

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

docker swarm join \
–token SWMTKN-1-0nmci78yvuxajrv216ggr7b0lj7w95hw7yetceexw5xxobealf-5dq4lguw11lkqjbhitrcnls1b \
172.18.0.1:2377

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

[root@instance-1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
e2luo3xtlpqdwvko6p5tvn38j * instance-1 Ready Active Leader

[root@instance-1 ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:

docker swarm join \
–token SWMTKN-1-0nmci78yvuxajrv216ggr7b0lj7w95hw7yetceexw5xxobealf-5dq4lguw11lkqjbhitrcnls1b \
172.18.0.1:2377

[root@instance-1 ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:

docker swarm join \
–token SWMTKN-1-0nmci78yvuxajrv216ggr7b0lj7w95hw7yetceexw5xxobealf-3rxc0y8s12a7jzfb083ce2l26 \
172.18.0.1:2377

[root@instance-1 ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND

[root@instance-1 ~]# docker service create –replicas 5 -p 80:80 –name web nginx
6kxmck5avpfs62vofbrs949r7

[root@instance-1 ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND
6kxmck5avpfs web 0/5 nginx

[root@instance-1 ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND
6kxmck5avpfs web 5/5 nginx

[root@instance-1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest 3f8a4339aadd 5 weeks ago 108.5 MB

[root@instance-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
848bd86e7746 nginx:latest “nginx -g ‘daemon off” About a minute ago Up About a minute 80/tcp web.5.1v4pds0c9ujb1bvxaohapjid3
cc121ab28bf5 nginx:latest “nginx -g ‘daemon off” About a minute ago Up About a minute 80/tcp web.2.cowioyhkqru2ycrubkqjti43j
fb4cf64cb97a nginx:latest “nginx -g ‘daemon off” About a minute ago Up About a minute 80/tcp web.3.3s3m6kmak4zr8z1xcum6x9yjp
c0e38c1eb304 nginx:latest “nginx -g ‘daemon off” About a minute ago Up About a minute 80/tcp web.4.97d7f0go0lgt9mgefqpyqqi0x
42da52ac1bbb nginx:latest “nginx -g ‘daemon off” About a minute ago Up About a minute 80/tcp web.1.8jmurey2ub0po9v1qlp1x9es7

[root@instance-1 ~]# docker service scale web=7
web scaled to 7

[root@instance-1 ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND
6kxmck5avpfs web 7/7 nginx

[root@instance-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c635abb3958 nginx:latest “nginx -g ‘daemon off” 13 seconds ago Up 12 seconds 80/tcp web.7.0ygu6cw13sbnmlfjymuqt3w6d
c01337f1caee nginx:latest “nginx -g ‘daemon off” 14 seconds ago Up 13 seconds 80/tcp web.6.a30buq27qed2h44u6utvp5pur
848bd86e7746 nginx:latest “nginx -g ‘daemon off” 3 minutes ago Up 3 minutes 80/tcp web.5.1v4pds0c9ujb1bvxaohapjid3
cc121ab28bf5 nginx:latest “nginx -g ‘daemon off” 3 minutes ago Up 3 minutes 80/tcp web.2.cowioyhkqru2ycrubkqjti43j
fb4cf64cb97a nginx:latest “nginx -g ‘daemon off” 3 minutes ago Up 3 minutes 80/tcp web.3.3s3m6kmak4zr8z1xcum6x9yjp
c0e38c1eb304 nginx:latest “nginx -g ‘daemon off” 3 minutes ago Up 3 minutes 80/tcp web.4.97d7f0go0lgt9mgefqpyqqi0x
42da52ac1bbb nginx:latest “nginx -g ‘daemon off” 3 minutes ago Up 3 minutes 80/tcp web.1.8jmurey2ub0po9v1qlp1x9es7

[root@instance-1 ~]# docker rm -f $(docker ps -qa)
8c635abb3958
c01337f1caee
848bd86e7746
cc121ab28bf5
fb4cf64cb97a
c0e38c1eb304
42da52ac1bbb
ec3c18be0ee6
[root@instance-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a2d5d3e9d9aa nginx:latest “nginx -g ‘daemon off” 6 seconds ago Up Less than a second 80/tcp web.7.17dqpwy13608uknwys6f1l23w
[root@instance-1 ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND
6kxmck5avpfs web 6/7 nginx
[root@instance-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
df6516f6788c nginx:latest “nginx -g ‘daemon off” 9 seconds ago Up 4 seconds 80/tcp web.4.dwsq5zb14a2461ex91gm6yyb9
bfad2664bf94 nginx:latest “nginx -g ‘daemon off” 10 seconds ago Up 5 seconds 80/tcp web.3.0ydeu05nglyyqsrqzs15pbbun
e6b5572dace2 nginx:latest “nginx -g ‘daemon off” 10 seconds ago Up 5 seconds 80/tcp web.2.3rycdm1iagn2lrwrwo3cqq6tt
21f804ef9a89 nginx:latest “nginx -g ‘daemon off” 11 seconds ago Up 5 seconds 80/tcp web.5.5hc71fr4p42omz6j0xkz3vba5
6bddfc82ea58 nginx:latest “nginx -g ‘daemon off” 11 seconds ago Up 6 seconds 80/tcp web.6.8p9aqgoetkftyr83ecoxd07i7
a2d5d3e9d9aa nginx:latest “nginx -g ‘daemon off” 12 seconds ago Up 6 seconds 80/tcp web.7.17dqpwy13608uknwys6f1l23w

[root@instance-1 ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND
6kxmck5avpfs web 7/7 nginx

[root@instance-1 ~]# docker service ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
5u0v9blp5je1726tvbspanvnp web.1 nginx instance-1 Running Running 2 minutes ago
8jmurey2ub0po9v1qlp1x9es7 \_ web.1 nginx instance-1 Shutdown Failed 2 minutes ago “task: non-zero exit (137)”
3rycdm1iagn2lrwrwo3cqq6tt web.2 nginx instance-1 Running Running 2 minutes ago
cowioyhkqru2ycrubkqjti43j \_ web.2 nginx instance-1 Shutdown Failed 2 minutes ago “task: non-zero exit (137)”
0ydeu05nglyyqsrqzs15pbbun web.3 nginx instance-1 Running Running 2 minutes ago
3s3m6kmak4zr8z1xcum6x9yjp \_ web.3 nginx instance-1 Shutdown Failed 2 minutes ago “task: non-zero exit (137)”
dwsq5zb14a2461ex91gm6yyb9 web.4 nginx instance-1 Running Running 2 minutes ago
97d7f0go0lgt9mgefqpyqqi0x \_ web.4 nginx instance-1 Shutdown Failed 2 minutes ago “task: non-zero exit (137)”
5hc71fr4p42omz6j0xkz3vba5 web.5 nginx instance-1 Running Running 2 minutes ago
1v4pds0c9ujb1bvxaohapjid3 \_ web.5 nginx instance-1 Shutdown Failed 2 minutes ago “task: non-zero exit (137)”
8p9aqgoetkftyr83ecoxd07i7 web.6 nginx instance-1 Running Running 2 minutes ago
a30buq27qed2h44u6utvp5pur \_ web.6 nginx instance-1 Shutdown Failed 2 minutes ago “task: non-zero exit (137)”
17dqpwy13608uknwys6f1l23w web.7 nginx instance-1 Running Running 2 minutes ago
0ygu6cw13sbnmlfjymuqt3w6d \_ web.7 nginx instance-1 Shutdown Failed 2 minutes ago “task: non-zero exit (137)”

[root@instance-1 ~]# docker service inspect web
[
{
“ID”: “6kxmck5avpfs62vofbrs949r7”,
“Version”: {
“Index”: 29
},
“CreatedAt”: “2018-02-05T04:05:22.394455005Z”,
“UpdatedAt”: “2018-02-05T04:08:28.889257448Z”,
“Spec”: {
“Name”: “web”,
“TaskTemplate”: {
“ContainerSpec”: {
“Image”: “nginx”
},
“Resources”: {
“Limits”: {},
“Reservations”: {}
},
“RestartPolicy”: {
“Condition”: “any”,
“MaxAttempts”: 0
},
“Placement”: {}
},
“Mode”: {
“Replicated”: {
“Replicas”: 7
}
},
“UpdateConfig”: {
“Parallelism”: 1,
“FailureAction”: “pause”
},
“EndpointSpec”: {
“Mode”: “vip”,
“Ports”: [
{
“Protocol”: “tcp”,
“TargetPort”: 80,
“PublishedPort”: 80
}
]
}
},
“Endpoint”: {
“Spec”: {
“Mode”: “vip”,
“Ports”: [
{
“Protocol”: “tcp”,
“TargetPort”: 80,
“PublishedPort”: 80
}
]
},
“Ports”: [
{
“Protocol”: “tcp”,
“TargetPort”: 80,
“PublishedPort”: 80
}
],
“VirtualIPs”: [
{
“NetworkID”: “9lix2yllwyzze18j9knhec33v”,
“Addr”: “10.255.0.4/16”
}
]
},
“UpdateStatus”: {
“StartedAt”: “0001-01-01T00:00:00Z”,
“CompletedAt”: “0001-01-01T00:00:00Z”
}
}
]

[root@instance-1 ~]# docker service rm web
web

[root@instance-1 ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND

[root@instance-1 ~]# docker swarm leave –force
Node left the swarm.

[root@instance-1 ~]# docker node ls
Error response from daemon: This node is not a swarm manager. Use “docker swarm init” or “docker swarm join” to connect this node to swarm and try again.

[root@instance-1 ~]# docker service create –replicas 3 -p 80:80 –name web jenkins
Error response from daemon: This node is not a swarm manager. Use “docker swarm init” or “docker swarm join” to connect this node to swarm and try again.

[root@instance-1 ~]# docker swarm init –advertise-addr 172.18.0.1
Swarm initialized: current node (d5j7hdg6thbwzxhf8hc1693qc) is now a manager.

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

docker swarm join \
–token SWMTKN-1-2cih35gcx2e8l9xd7ocknsarp6lyxv869otfh42np0ol9tuizz-5gs7jf4m23fbshoyy46g2s4jg \
172.18.0.1:2377

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

[root@instance-1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
d5j7hdg6thbwzxhf8hc1693qc * instance-1 Ready Active Leader

[root@instance-1 ~]# docker service create –replicas 3 -p 80:8080 –name myjenkins jenkins
dekidxcjxzrq88gpvp091njcv

[root@instance-1 ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND
dekidxcjxzrq myjenkins 3/3 jenkins

[root@instance-1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f1c27db5aec jenkins:latest “/bin/tini — /usr/lo” 59 seconds ago Up 57 seconds 8080/tcp, 50000/tcp myjenkins.2.4zczah4bor89ub6yl52hes55y
3c59350a7b4e jenkins:latest “/bin/tini — /usr/lo” 59 seconds ago Up 57 seconds 8080/tcp, 50000/tcp myjenkins.1.d7d09jly91f00bp8va469zoqc
86e8bd6bff36 jenkins:latest “/bin/tini — /usr/lo” 59 seconds ago Up 57 seconds 8080/tcp, 50000/tcp myjenkins.3.2otdaly1b40zus3u4wu41nphb

[root@instance-1 ~]# docker exec -it 6f1c27db5aec cat /var/jenkins_home/secrets/initialAdminPassword
ff2cdc4149c14326a7f03f31cbc52021

 

Leave a comment