Sharing files between container and host

2019-07-13 10:57发布

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.

I appreciate your help.

Thanks. :)

标签: docker
1条回答
相关推荐>>
2楼-- · 2019-07-13 11:15

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.

查看更多
登录 后发表回答