Docker: Volumes, networks & remote hosts in depth
12 Docker commands: Volumes, networks & remote hosts in depth. Click a command to see what each part does.
Docker: Volumes, networks & remote hosts in depthIndex
- Whole sheet120
- Basics: images & containers11
- Volumes & networks4
- Find & inspect containers7
- Environment variables & container config12
- Software versions inside containers & images9
- Logs & shells5
- Run containers3
- Images4
- Cleanup6
- Docker Compose v27
- Container lifecycle & live changes10
- Builds, multi-platform & moving images11
- Volumes, networks & remote hosts in depth12
- Compose: more commands9
- Swarm mode10
Volumes, networks & remote hosts in depth12
docker volume inspect <volume>; docker ps -a --filter volume=<volume>Where is a volume's data and who uses it?What each part does
docker volume inspectdriver, mountpoint on the host, labelsdocker ps -a --filter volume=<volume>containers using it
docker run --rm -v <volume>:/data:ro -v "$PWD":/backup alpine tar czf /backup/<volume>.tgz -C /data .Back up a volume to a tar fileWhat each part does
docker run --rmthrowaway helper container-v <volume>:/data:romount the volume read-only-v "$PWD":/backupmount the current host folderalpine tar czf ... -C /data .archive the volume contents into the host folder
Tip Stop the app first (or use its own dump tool) for consistent database backups.
docker run --rm -v <volume>:/data -v "$PWD":/backup alpine tar xzf /backup/<volume>.tgz -C /dataRestore a volume from a tar fileCautionWhat each part does
-v <volume>:/datamount the target volume read-writetar xzf ... -C /dataunpack the backup into it
docker volume prune -aRemove unused volumesDestructiveWhat each part does
docker volume prunedelete volumes no container uses-ainclude named volumes (without it, only anonymous ones on Docker 23+)
docker network inspect <network> --format '{{json .IPAM.Config}} {{range .Containers}}{{.Name}} {{.IPv4Address}}; {{end}}'Inspect a network: subnet and connected containersWhat each part does
docker network inspect <network>network details{{json .IPAM.Config}}subnet and gateway{{range .Containers}}...{{end}}each attached container with its IP
docker network connect <network> <container>; docker network disconnect <network> <container>Connect / disconnect a running container to a networkWhat each part does
docker network connectattach to another network (containers can be on several)docker network disconnectdetach
docker run --rm --network host <image>; docker run --rm --network none <image>Run with host or no networkingWhat each part does
--network hostshare the host's network stack: no port mapping, no isolation (Linux only)--network noneno network at all, only loopback
docker network prune -fRemove unused networksCautionWhat each part does
docker network prunedelete networks no container uses-fno prompt
docker context create <name> --docker host=ssh://<user>@<host>; docker context use <name>Run docker commands against a remote hostWhat each part does
docker context createsave a named connection to another Docker daemon--docker host=ssh://<user>@<host>connect over SSH (no exposed TCP port needed)docker context use <name>make it the default; docker context use default to come back
DOCKER_HOST=ssh://<user>@<host> docker psOne-off command on a remote daemonWhat each part does
DOCKER_HOST=ssh://...point this one command at another daemondocker psany docker command
cat /etc/docker/daemon.json; journalctl -u docker -n 100 --no-pagerCheck the daemon config and its logsWhat each part does
/etc/docker/daemon.jsondaemon settings: log driver and rotation, registry mirrors, data-root, address poolsjournalctl -u dockerthe daemon's own logs (start errors, pull failures)
docker info --format '{{.DockerRootDir}} {{.Driver}} {{.LoggingDriver}} {{.CgroupDriver}}'Where does Docker store its data?What each part does
{{.DockerRootDir}}data directory, usually /var/lib/docker{{.Driver}}storage driver (overlay2){{.LoggingDriver}}default log driver (json-file, local, journald){{.CgroupDriver}}systemd or cgroupfs
Nothing matches.
My DevOps Playbook by Angelo John Calleja