Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share folder from docker container to host

Tags:

docker

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"

like image 728
user3331089 Avatar asked Jan 24 '17 14:01

user3331089


1 Answers

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

like image 160
Salem Avatar answered Nov 09 '22 06:11

Salem