Skip to content

Docker

Status

Show status of swarm nodes:

shell
docker node ls

Show global status of services and replicas:

shell
docker service ls

List status of all stack services that should be running across all nodes:

shell
docker stack ps smarthealth-app --no-trunc | grep -v '\\_'

List status of a single service that should be running across all nodes:

shell
docker service ps smarthealth-app_php --no-trunc | grep -v '\\_'

List status of all containers across all nodes (quiet or rescheduled ones too):

shell
docker node ps $(docker node ls -q)

List status of all services and containers running on this node:

shell
docker ps -a

Show status of containers that should be running on this node:

shell
docker node ps $(docker node ls -q) | grep -v '\\_'

Alternative with duplicates:

shell
docker node ps $(docker node ls -q) --filter "desired-state=running"

Show info about a service:

shell
docker service inspect smarthealth-app_cloudflared --pretty | less

Inspect a container:

shell
docker inspect u981s5m24azw | less

Logs

Show logs of a service (across all nodes):

shell
docker service logs smarthealth-app_php

Show logs of a service (current node only):

bash
docker logs $(docker ps -q -f name=smarthealth-app_php)

Show real-time swarm events

shell
docker events

Real-time logs:

shell
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:

shell
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.

shell
docker exec CONTAINERID sh -c 'php artisan --version'

Deploy the stack and (re)start the changed services:

shell
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):

shell
docker service update --force smarthealth-app_php

(Re)start all services and containers (in the background):

shell
docker service ls -q | xargs -n1 docker service update --force --detach

Scale the scheduler container down to 0 replicas (i.e. stop all containers):

shell
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.

shell
docker node update --availability drain NODEID

Turn a swarm node back on:

shell
docker node update --availability active NODEID

Create a network if it doesn't exist yet:

shell
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:

shell
docker network rm smarthealth

DANGER

This deletes all services, containers, and networks without warning

shell
docker stack rm smarthealth-app