From 397ca469cd3fe838aa508e6ffbfc9a3c497cfe72 Mon Sep 17 00:00:00 2001 From: Gaurav Nayak Date: Fri, 20 Mar 2026 19:02:26 +0530 Subject: [PATCH] docs: add missing answers for docker storage,networking and data management questions --- topics/containers/README.md | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/topics/containers/README.md b/topics/containers/README.md index 060f62588c..37ec9bc6d4 100644 --- a/topics/containers/README.md +++ b/topics/containers/README.md @@ -986,11 +986,34 @@ shim is the process that becomes the container's parent when runc process exists
How would you transfer data from one container into another?
+There are several ways: + +1. Using a shared volume: + + docker run -v shared_data:/data container1 + docker run -v shared_data:/data container2 + +2. Using docker cp to copy from container to host, then to another container: + + docker cp container1:/path/to/file /tmp/file + docker cp /tmp/file container2:/path/to/file + +3. Using a network - containers on the same Docker network + can transfer data via HTTP, TCP, etc.
What happens to data of the container when a container exists?
+When a container exits, the data in its writable layer is preserved +but NOT deleted - it still exists until the container is explicitly +removed with docker rm. +However, once the container is removed, all data in the writable +layer is permanently lost. + +To persist data beyond the container lifecycle, use volumes: + + docker run -v myvolume:/data myimage
How do you remove old, non running, containers?
@@ -1029,15 +1052,54 @@ Because each container has its own writable container layer, and all changes are
How do you manage persistent storage in Docker?
+There are three options: + +1. Volumes (recommended) - managed by Docker, + stored in /var/lib/docker/volumes/: + + docker volume create myvolume + docker run -v myvolume:/app/data myimage + +2. Bind mounts - mount a host directory directly: + docker run -v /host/path:/container/path myimage + +3. tmpfs mounts - stored in host memory only, + not persisted to disk: + + docker run --tmpfs /tmp myimage + +Volumes are preferred in production as they are portable, +easy to back up and independent of host directory structure.
How can you connect from the inside of your container to the localhost of your host, where the container runs?
+Use the special DNS name host.docker.internal which +resolves to the host machine IP: + + curl http://host.docker.internal:8080 + +On Linux, you may need to add --add-host flag: + docker run --add-host=host.docker.internal:host-gateway myimage + +Alternatively find the host IP using: + + ip route | grep default | awk '{print $3}'
How do you copy files from Docker container to the host and vice versa?
+Use the docker cp command: + + # From container to host + docker cp :/path/in/container /path/on/host + + # From host to container + docker cp /path/on/host :/path/in/container + # Example + docker cp mycontainer:/app/logs/app.log /tmp/app.log + docker cp /tmp/config.yml mycontainer:/app/config.yml ### Docker Compose