简体   繁体   中英

How to make a docker container directory accesible from host?

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM