Share folder from docker container to host

2019-06-23 04:48发布

问题:

Is there a way to share folder from docker container to host?

For example I have tomcat inside docker container and I want it to be visible from the outside.

If I do volumes: - /opt/tomcat:/opt/tomcat

I receive an error in the container: "No such file or directory /opt/tomcat/bin/catalina.sh"

回答1:

I don't think Docker allows you to that. That command will mount your host folder in the container, so your files in the container are not visible anymore.

Two options:

  1. You can access the container files using this trick (GitHub issue): sudo ls /proc/$(docker inspect --format {{.State.Pid}} YOUR_CONTAINER_NAME)/root. To access them you will need root privileges, or you can use bindfs to match root user with your user name (see the same thread).

  2. Create a new volume, copy the files you need to be accessible to there and mount it inside the container, in the right place



标签: docker