Skip to content

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.

Index
12 items
Click a command to see what each part does.

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

    1. docker volume inspectdriver, mountpoint on the host, labels
    2. docker 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 file

    What each part does

    1. docker run --rmthrowaway helper container
    2. -v <volume>:/data:romount the volume read-only
    3. -v "$PWD":/backupmount the current host folder
    4. alpine 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 fileCaution

    What each part does

    1. -v <volume>:/datamount the target volume read-write
    2. tar xzf ... -C /dataunpack the backup into it
  • docker volume prune -aRemove unused volumesDestructive

    What each part does

    1. docker volume prunedelete volumes no container uses
    2. -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 containers

    What each part does

    1. docker network inspect <network>network details
    2. {{json .IPAM.Config}}subnet and gateway
    3. {{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 network

    What each part does

    1. docker network connectattach to another network (containers can be on several)
    2. docker network disconnectdetach
  • docker run --rm --network host <image>; docker run --rm --network none <image>Run with host or no networking

    What each part does

    1. --network hostshare the host's network stack: no port mapping, no isolation (Linux only)
    2. --network noneno network at all, only loopback
  • docker network prune -fRemove unused networksCaution

    What each part does

    1. docker network prunedelete networks no container uses
    2. -fno prompt
  • docker context create <name> --docker host=ssh://<user>@<host>; docker context use <name>Run docker commands against a remote host

    What each part does

    1. docker context createsave a named connection to another Docker daemon
    2. --docker host=ssh://<user>@<host>connect over SSH (no exposed TCP port needed)
    3. 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 daemon

    What each part does

    1. DOCKER_HOST=ssh://...point this one command at another daemon
    2. docker psany docker command
  • cat /etc/docker/daemon.json; journalctl -u docker -n 100 --no-pagerCheck the daemon config and its logs

    What each part does

    1. /etc/docker/daemon.jsondaemon settings: log driver and rotation, registry mirrors, data-root, address pools
    2. journalctl -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

    1. {{.DockerRootDir}}data directory, usually /var/lib/docker
    2. {{.Driver}}storage driver (overlay2)
    3. {{.LoggingDriver}}default log driver (json-file, local, journald)
    4. {{.CgroupDriver}}systemd or cgroupfs

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…