How to make a docker container directory accesible from host?

99封情书 提交于 2019-12-10 08:50:23

问题


I have a tomcat running in a docker container and would like to watch was is going on in the webapps directory from the docker host. Is it possible to do this by mounting a volume without setting up a sshd in the container and without starting a shell inside?


回答1:


Instead of mounting volume, you could open a new bash in your running container with docker exec:

docker exec -it <id of running container> bash

That way, you can directly go to the folder managed by the webapp from within the container.




回答2:


You can declare some local folder on your host machine as the webapps folder of tomcat.

docker run -d -v $(pwd)/webapps:/path/to/tomcat/webapps yourimage/tomcat

Afterwards Tomcat will write to the local folder and you can view it! The existing folder will not be visible as long as the folder is mounted.

You can declare a volume and then start a second container to mount and browse it!

docker run -d --name tomcat -v /path/to/tomcat/webapps yourimage/tomcat
docker run -it --volumes-from tomcat yourimage/tomcat bash

Has the advantage that the current folder is copied inside the volume.



来源:https://stackoverflow.com/questions/31569846/how-to-make-a-docker-container-directory-accesible-from-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!