Linux/Docker/Swarm: Difference between revisions
m (→Stats / Info) |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 18: | Line 18: | ||
docker service ls | docker service ls | ||
docker service inspect service1 --pretty | |||
docker node ps node1 node2 node3 | |||
</pre> | </pre> | ||
Line 27: | Line 31: | ||
docker node rm node1 | docker node rm node1 | ||
docker node inspect node1 | docker node inspect node1 | ||
docker node inspect --pretty node1 | |||
docker node update --role manager node1 | docker node update --role manager node1 | ||
docker node update --availability drain node1 # pause node and move load to other nodes | |||
docker node update --availability active node1 # unpause and send back to work | |||
from node: | from node: | ||
Line 33: | Line 42: | ||
</pre> | </pre> | ||
== Services == | |||
<pre> | |||
docker service create --replicas 4 --name service1 alpine ping google.com | |||
docker service ls # list services | |||
docker service ps service1 # list instances of service on nodes | |||
docker service logs service1 -f | |||
docker service scale service1=0 | |||
docker service rm service1 | |||
docker service update --image alpine service1 | |||
</pre> | |||
== Enable local insecure HTTP registry == | |||
<pre> | |||
echo '''{ "insecure-registries": [ "vm-docker0:5000" ] }''' > /etc/docker/daemon.json | |||
</pre> | |||
== Stack == | |||
* docker-compose.yml | |||
<pre> | |||
version: '3.9' | |||
services: | |||
http: | |||
image: nginxdemos/hello:latest | |||
ports: | |||
- "80:80" | |||
deploy: | |||
replicas: 4 | |||
update_config: | |||
parallelism: 2 | |||
delay: 10s | |||
restart_policy: | |||
condition: on-failure | |||
resources: | |||
limits: | |||
cpus: "0.1" | |||
memory: 1G | |||
</pre> | |||
<pre> | |||
docker stack deploy -c docker-compose.yml hello | |||
docker stack ls | |||
docker stack ps hello | |||
docker stack services hello | |||
docker stack rm hello | |||
</pre> | |||
[[Category:Linux/Docker]] | [[Category:Linux/Docker]] | ||
[[Category:Linux]] | [[Category:Linux]] |
Latest revision as of 19:52, 10 December 2021
Create swarm
- on manager
docker swarm init --advertise-addr <MANAGER-IP> -> copy command from here to join from nodes. e.g.: docker swarm join --token SWMTKN-1-5fs8k04yvhalpcok7xa8ktryuin55w4gt1wf1aaj9vawwh52hx-1uk9i6yz3q7j7bzuqdun2xqwy 192.168.1.226:2377
- show token
docker swarm join-token manager
Stats / Info
docker node ls docker service ls docker service inspect service1 --pretty docker node ps node1 node2 node3
Manage nodes
from manager: docker node promote node1 docker node demote node1 docker node rm node1 docker node inspect node1 docker node inspect --pretty node1 docker node update --role manager node1 docker node update --availability drain node1 # pause node and move load to other nodes docker node update --availability active node1 # unpause and send back to work from node: docker swarm leave
Services
docker service create --replicas 4 --name service1 alpine ping google.com docker service ls # list services docker service ps service1 # list instances of service on nodes docker service logs service1 -f docker service scale service1=0 docker service rm service1 docker service update --image alpine service1
Enable local insecure HTTP registry
echo '''{ "insecure-registries": [ "vm-docker0:5000" ] }''' > /etc/docker/daemon.json
Stack
- docker-compose.yml
version: '3.9' services: http: image: nginxdemos/hello:latest ports: - "80:80" deploy: replicas: 4 update_config: parallelism: 2 delay: 10s restart_policy: condition: on-failure resources: limits: cpus: "0.1" memory: 1G
docker stack deploy -c docker-compose.yml hello docker stack ls docker stack ps hello docker stack services hello docker stack rm hello