A container started from inside a container sees an empty or missing mount
the mounted folder is empty inside the new containerShort answer
A bind mount is resolved by the Docker daemon, on the daemon's own host, not inside the container that typed the command. From a CI job with the host socket, the path you give must exist on the host. With -v, a missing path is created as an empty directory, which looks like an empty mount.
Fix it fast
1Find out which cause you have
Find out which daemon is receiving your commands and whether the path you mount exists there. Run this inside the job or container that starts the other containers.
ls -l /var/run/docker.sock docker info docker run --rm -v "$PWD":/work alpine ls -la /work2Match what you see, then jump to its fix
- 1
ls -la /work in the second container is empty, or the path is not what you expectThe path exists in your container but not on the daemon hostFix - 2
No error, but the mount point is an empty directory owned by root-v silently created an empty directory for a missing sourceFix - 3
The job talks to a docker:dind service over tcp://...:2376, and host paths are not visible to itA nested daemon (dind) has its own filesystemFix
- 1
What does the error look like?
the mounted folder is empty inside the new containerthe files you mounted are not there in the second container
Cause 1 of 3
The path exists in your container but not on the daemon host
1Check
The docker CLI only sends your request. Bind mounts are created on the Docker daemon host, not on the client. When the CLI container shares the host's /var/run/docker.sock, the daemon is the host's, so $PWD (a path that only exists inside the job container, such as a CI workspace) points at nothing on the host.
docker run --rm -v "$PWD":/work alpine ls -la /work
docker info2Fix
Give the daemon a path that really exists on the host. Either mount the same host folder into your job container at the same absolute path, so the two views match, or move the data into a named volume and use that volume in both containers.
# job container sees the host folder at the SAME path
docker run -v /srv/ci/work:/srv/ci/work -v /var/run/docker.sock:/var/run/docker.sock docker sh
# second container: use a named volume instead of a path
docker volume create build_data
docker run --rm -v build_data:/work alpine ls -la /work3Verify
The folder inside the second container now lists the files you expect.
docker run --rm -v /srv/ci/work:/work alpine ls -la /workConfirmed by docs.docker.com
Cause 2 of 3
-v silently created an empty directory for a missing source
1Check
With -v, Docker creates the source as a directory when it does not exist on the host. With --mount it does not: it returns an error unless bind-create-src is set. So a wrong path with -v fails quietly and with --mount fails loudly.
ls -ld /srv/ci/work2Fix
Use --mount while debugging so a wrong path stops the run, and fix the path. Remove the stray empty directory so it does not hide the mistake later.
docker run --rm --mount type=bind,source=/srv/ci/work,target=/work alpine ls -la /work3Verify
With the right source the command lists your files, and with a wrong one it now prints an error instead of an empty folder.
docker run --rm --mount type=bind,source=/srv/ci/typo,target=/work alpine ls /workConfirmed by docs.docker.com
Cause 3 of 3
A nested daemon (dind) has its own filesystem
1Check
With Docker-in-Docker, the daemon runs inside its own container, so bind sources are resolved there. The official image shares files with the client container through a named volume: its TLS example mounts the same volume into both. It also says --privileged is required for dind.
docker ps2Fix
Share what the nested daemon must read through a named volume mounted into the client and the dind container, as the image's own certificate setup does. If you only need the host's daemon, mount the host socket and use the host-path fix above instead of running dind.
docker volume create shared_work
docker run --privileged --name dind -d \
-v shared_work:/work docker:dind3Verify
The client container and the dind daemon list the same files in /work.
docker exec dind ls -la /workConfirmed by github.com
How do I stop it coming back?
- Decide per pipeline: host socket (paths are host paths) or dind (paths belong to the nested daemon). Do not mix the two.
- Prefer named volumes over bind mounts for files that two containers must share.
- Use --mount in scripts so a wrong source path stops the run.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Docker says permission denied when your user runs a command
Got permission denied while trying to connect to the Docker daemon socket
Your user is not allowed to open /var/run/docker.sock.
3 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fix