3

I'm running a docker container with a volume /var/my_folder. The data there is persistent: When I close the container it is still there. But also want to have the data available on my host, because I want to work on code with an IDE, which is not installed in my container.

So how can I have a folder /var/my_folder on my host machine which is also available in my container?

I'm working on Linux Mint.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
hideous
  • 352
  • 3
  • 10

1 Answers1

4

Link : Manage data in containers

The basic run command you want is ...

docker run -dt --name containerName -v /path/on/host:/path/in/container

The problem is that mounting the volume will, (for your purposes), overwrite the volume in the container

the best way to overcome this is to create the files (inside the container) that you want to share AFTER mounting.

The ENTRYPOINT command is executed on docker run. Therefore, if your files are generated as part of your entrypoint script AND not as part of your build THEN they will be available from the host machine once mounted.

The solution is therefore, to run the commands that creates the files in the ENTRYPOINT script.

Failing this, during the build copy the files to another directory and then COPY them back in your ENTRYPOINT script.

harrymc
  • 1,069
  • 8
  • 33
danday74
  • 52,471
  • 49
  • 232
  • 283
  • Thanks for your answer! But when my volume contains a git repository I'll not have to handle this problem, am I right? – hideous Apr 15 '16 at 17:56
  • Addendum: While executing your command I get this message: docker: "run" requires a minimum of 1 argument. See 'docker run --help'. – hideous Apr 15 '16 at 18:16
  • Apologies I think name must be last argument – danday74 Apr 15 '16 at 20:35
  • If the repo is insid your container then git clone in your ENTRYPOINT script, if it's on host then it will just work – danday74 Apr 15 '16 at 20:36