Home > database >  How to mount file inside docker in docker?
How to mount file inside docker in docker?

Time:08-29

docker container start with

- /var/run/docker.sock:/var/run/docker.sock

Inside docker container i want to call another docker something like this

docker run --rm --net none -v /new/test.py:/new/test.py test-python timeout 5 make --silent -C /new/ test

but i get an error

docker: Error response from daemon: failed to create shim: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting to rootfs flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

Without the -v parameter, the launch itself is processed

and When I call the same code not from the docker, everything works out

What could be the reason?

CodePudding user response:

Remember, while you may have exposed the docker socket inside your container, the docker daemon is running on your host. It's not inside any container. So when you write:

... -v /new/test.py:/new/test.py ...

Docker is looking for /new/test.py relative to the root of your host filesystem, not inside the container filesystem.

In general, bind mounts aren't going to work in a useful fashion. Named volumes will work fine, of course.

  • Related