Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Some useful docker commands:

docker stack ls
List stacks or apps

docker stack deploy -c <composefile> <appname>
Run the specified Compose file

docker service ls
List running services associated with an app

docker service ps <service>
List tasks associated with an app

docker inspect <task or container>
Inspect task or container

docker container ls -q
List container IDs

docker stack rm <appname>
Tear down an application

docker swarm leave --force
Take down a single node swarm from the manager

#docker #cheatsheet #inspect #stack #swarm #service
Removing docker network in swarm mode gives error below:
Error response from daemon: network demo_net has active endpoints

In order to remove the network you need to remove dangling containers that are bound to the network, to see those containers:
docker network inspect demo_net

In Containers section you would see name of those containers. Grab the name of the container and use disconnect as below to remove it from the network:
docker network disconnect -f demo_net NAME_OF_YOUR_CONTAINER

#docker #network #disconnect #swarm
If your in docker swarm and you want to see log data of a specific service you can use --since as below:

docker service logs project_redis --since "1m" -f

It sometimes has unexpected behaviours and does not print logs. Rather than --since you can use tail it is better in case you want to see recent logs:

docker service logs project_redis --tail 1

#docker #swarm #since #tail #log
Kill zombie tasks in docker swarm using steps below:

1- docker ps --no-trunc to find the zombie container id.

2- At the host the container running in, look up the PID of a docker-containerd-shim process by ps aux | grep <container id>

3- kill <PID>

It sweeps entries of the zombie tasks from swarm. Happy deploying! :)

#docker #swarm #zombie #no_trunk #shim
In docker swarm mode you can list nodes with docker node ls. If you want to assign a label to each node you can use the below command to update node labels. For example you can assign a key=value pair like role=storage to one of your node listed with the first command:

docker node update --label-add role=storage YOUR_HOSTNAME

Read more here:
- https://docs.docker.com/engine/swarm/manage-nodes/#update-a-node

The great thing about this labeling is in docker compose file that you can tell docker which server should get deployed on which server (node):

deploy:
replicas: 4
placement:
constraints:
- node.labels.role == storage

NOTE: role is something that we ourselves have been defined. You can define your own as requirements vary.


#docker #node #swarm #label #role