Docker
Status
Show status of swarm nodes:
docker node lsShow global status of services and replicas:
docker service lsList 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 -aShow 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 | lessInspect a container:
docker inspect u981s5m24azw | lessLogs
Show logs of a service (across all nodes):
docker service logs smarthealth-app_phpShow logs of a service (current node only):
docker logs $(docker ps -q -f name=smarthealth-app_php)Show real-time swarm events
docker eventsReal-time logs:
docker service logs --follow --timestamps --no-trunc smarthealth-app_phpSee: 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-appRestart 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 --detachScale the scheduler container down to 0 replicas (i.e. stop all containers):
docker service scale smarthealth-app_scheduler=0Drain a node and shut down all its services:
Note: use docker node ls to list all swarm nodes.
docker node update --availability drain NODEIDTurn a swarm node back on:
docker node update --availability active NODEIDCreate a network if it doesn't exist yet:
docker network ls | grep -q 'smarthealth' || docker network create --driver overlay smarthealthDANGER
This deletes the network some containers might rely on
Delete a network:
docker network rm smarthealthDANGER
This deletes all services, containers, and networks without warning
docker stack rm smarthealth-app