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. :)
答案 0 :(得分:3)
您想要的基本运行命令是......
docker run -dt --name containerName -v /path/on/host:/path/in/container
问题是安装卷会(为了您的目的)覆盖容器中的卷
解决此问题的最佳方法是在安装后创建要共享的文件(容器内)。
在docker run上执行ENTRYPOINT命令。因此,如果您的文件是作为入口点脚本的一部分生成的,而不是作为构建的一部分生成的那么,一旦安装,它们就可以从主机上获得。
因此,解决方案是运行在ENTRYPOINT脚本中创建文件的命令。
如果失败,在构建期间将文件复制到另一个目录,然后在ENTRYPOINT脚本中将它们复制回来。