Docker
Status
Show status of swarm nodes:
docker node ls
Show global status of services and replicas:
docker service ls
List status of all stack services that should be running across all nodes:
docker stack ps smarthealth-app --no-trunc | grep -v '\\_'
List status of a single service that should be running across all nodes:
docker service ps smarthealth-app_php --no-trunc | grep -v '\\_'
List status of all containers across all nodes (quiet or rescheduled ones too):
docker node ps $(docker node ls -q)
List status of all services and containers running on this node:
docker ps -a
Show status of containers that should be running on this node:
docker node ps $(docker node ls -q) | grep -v '\\_'
Alternative with duplicates:
docker node ps $(docker node ls -q) --filter "desired-state=running"
Show info about a service:
docker service inspect smarthealth-app_cloudflared --pretty | less
Inspect a container:
docker inspect u981s5m24azw | less
Logs
Show logs of a service (across all nodes):
docker service logs smarthealth-app_php
Show logs of a service (current node only):
docker logs $(docker ps -q -f name=smarthealth-app_php)
Show real-time swarm events
docker events
Real-time logs:
docker service logs --follow --timestamps --no-trunc smarthealth-app_php
See: https://docs.docker.com/reference/cli/docker/service/logs
Show when services were last updated:
docker stack services smarthealth-app --format '{{.Name}}' | xargs -I {} docker service inspect --format '{{.Spec.Name}} was updated at {{.UpdatedAt}}' {}
Actions
Execute a command in a container (running on the current node).
Tip: use docker ps
to get a list of running containers first.
docker exec CONTAINERID sh -c 'php artisan --version'
Deploy the stack and (re)start the changed services:
cd /home/smarthealth/smarthealth-app/config
docker stack deploy --compose-file docker-swarm-production.yml --prune smarthealth-app
Restart a service (rolling restart across all nodes):
docker service update --force smarthealth-app_php
(Re)start all services and containers (in the background):
docker service ls -q | xargs -n1 docker service update --force --detach
Scale the scheduler container down to 0 replicas (i.e. stop all containers):
docker service scale smarthealth-app_scheduler=0
Drain a node and shut down all its services:
Note: use docker node ls
to list all swarm nodes.
docker node update --availability drain NODEID
Turn a swarm node back on:
docker node update --availability active NODEID
Create a network if it doesn't exist yet:
docker network ls | grep -q 'smarthealth' || docker network create --driver overlay smarthealth
DANGER
This deletes the network some containers might rely on
Delete a network:
docker network rm smarthealth
DANGER
This deletes all services, containers, and networks without warning
docker stack rm smarthealth-app