
How to Back Up and Restore Docker Volumes Without Surprises
Back up a Docker volume with a throwaway container and tar, restore it into a fresh volume, handle running databases correctly and verify the archive.
Tag
38 posts

Back up a Docker volume with a throwaway container and tar, restore it into a fresh volume, handle running databases correctly and verify the archive.

Learn when to use a Docker volume and when a bind mount: syntax with --mount, read-only mounts, what survives docker rm, and the permission trap.

Run a script when a Docker container starts using an entrypoint, an init directory or Compose; keep PID 1 correct with exec and handle one-time setup safely.

Use the Go Docker SDK to list, start and inspect containers: create a client from the environment, negotiate the API version, stream logs and pull images.

Dump and restore a database in Docker: pg_dump and mysqldump via docker exec, volume backups, consistency, restoring into a new container and speed.

Read Docker container logs with docker logs, filter by time, set up json-file rotation with max-size and max-file, and choose another driver for production.

Run cron inside a Docker container the right way: install it, pass environment variables, log to stdout, handle PID 1, and know when a sidecar is better.

Run integration tests against real databases in CI with service containers: GitHub and GitLab syntax, health checks, ports and host names.

Use VS Code Remote SSH and Dev Containers: connect with your ssh config, devcontainer.json, features, ports and the problems to expect.

Run Docker Compose in production on a single server: restart policies, healthchecks, secrets, a reverse proxy, resource limits, logs, updates and backups.

Clean up Docker disk space safely: docker system df, prune for containers, images, networks and the build cache, why volumes need care, and filters.

Limit CPU and memory for Docker containers with --memory, --cpus and Compose limits, read OOM kills, check usage with docker stats and avoid the swap trap.