Symbolic Link Host to Docker Container
Asked Answered
B

4

7

Well, Basically I wanna create a Symbolic link "ln -s" from my host to my container.

To sum up: the host folder .m2 of the host must have a Symbolic link to the .m2 folder inside my container, something like: $ ln -s containerIp:/root/.m2 myContainerAlias

I've seen the below posts but they didn't help me since I don't wanna copy the files to my local host.

Docker - copy file from container to host

Apache in Docker says: Symbolic link not allowed

https://omarabid.com/symlink-to-a-mounted-volume-in-docker/

Edited:

I've found another valuable Issue here:

How to mount a directory in the docker container to the host? Thanks...

Bouie answered 5/2, 2016 at 17:52 Comment(0)
B
1

For further investigation about this question. I would like to notify that I've "solved" my issue with the same approach than @Kai Hofstetter in the following post: How to mount a directory in the docker container to the host?

Bouie answered 10/2, 2016 at 19:30 Comment(1)
How did you solve it? The approach mentioned in the linked question uses copy and it is really inefficient (space, time) ... There is no better solution?Volition
S
1

Sounds like you're trying to optimize a Maven build running inside a container?

docker run -it --rm -w /opt/maven \
   -v $PWD:/opt/maven \
   -v $HOME/.m2:/root/.m2 \
   maven:3.3-jdk-8 \
   mvn clean install

Example

Sport answered 6/2, 2016 at 8:5 Comment(2)
Thanks for answering, Mark O'Connor, but what I really want is the opposite of that, I don't want to have the .m2 in my host machine, only in the container (already setted in the DockerFIle in the build time), and this way, all other developers that is going to use the container, won't have to download the files in their own hosts.Bouie
@Bouie This is how the Maven works by default (jars are cached under "/root/.m2"). Personally I think shared jars between developers using files inside a container is a bit inflexible. An alternative would be to run an instance of Nexus allowing you to locally cache jars for all developers within your organisation. See the following for an example #27767764Paucker
B
1

For further investigation about this question. I would like to notify that I've "solved" my issue with the same approach than @Kai Hofstetter in the following post: How to mount a directory in the docker container to the host?

Bouie answered 10/2, 2016 at 19:30 Comment(1)
How did you solve it? The approach mentioned in the linked question uses copy and it is really inefficient (space, time) ... There is no better solution?Volition
R
0

If you want to share data between the host and a container, or visa versa, you need to use a docker volume.

There are many ways to do this, but for your situation the easiest is to mount a host directory as a data volume. This is done with the -v flag with docker. For example docker run -it -v /path/to/.m2:/root/.m2 ubuntu:latest /bin/bash will run the ubuntu:latest image with the host directory /path/to/.m2 'symlinked' to the container directory /root/.m2.

Hope that helps.

Romany answered 6/2, 2016 at 4:26 Comment(1)
Hi JamesStewy, first of all thanks for answering... Well, I'm using volume already for another purpose, and as far as I'm concerned to use it, I need to have the files in my host to mirror them in the container (Correct me if I'm worng please). Furthermore, What I really want is only reference the dependencies files inside the .m2 directory doing that from my host (without having the dependencies inside my host).Bouie
B
0

Nope, you can not create symlink between host and containers. refer to Mount host directory with a symbolic link inside in docker container

one solution is mount the volumes at the start moment:

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

Bravo answered 16/12, 2020 at 0:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.