Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mount host directory with a symbolic link inside in docker container

Tags:

docker

People also ask

Does Docker support symlinks?

Docker doesn't support symlinking files outside the build context.

How do I mount my current working directory to my Docker container in Windows?

Open Settings on Docker Desktop (Docker for Windows). Select Shared Drives. Select the drive that you want to use inside your containers (e.g., C). Click Apply.


Symlinks are a big challenge inside docker. In your case you can mount both directories:

-v /home/test/:/home/test -v /mnt/mountedfile:/mnt/mountedfile

For symbolic links to work both inside and outside the container, they have to be absolute paths and use exactly the same names.

In general, symlinks do not work inside docker. I found this the hard way.


One solution is to make Docker mount the original file, but use readlink -f which prints the file's actual location. This way, you can still reference the symlink location in your command, e.g.

docker run -it -v $(readlink -f /home/test/):/home/test/ ...