Alok Singh
Alok Singh

Reputation: 11

Docker container not showing volume mounted - Access issue

root@centdev01$ grep -e CMD -e RUN Dockerfile
RUN apt-get update 
RUN apt-get -y install ruby ruby-dev build-essential redis-tools
RUN gem install --no-rdoc --no-ri sinatra json redis
RUN mkdir -p /opt/webapp
RUN chmod 777 /opt/webapp
CMD ["/opt/webapp/bin/webapp"]

root@centdev01$ docker build -t "alok87/sinatra" .

root@centdev01$ docker run -d -p 80 --name ubunsin10 -v $PWD/webapp:/opt/webapp alok87/sinatra
25ekgjalgjal25rkg
root@centdev01$ docker logs ubunsin10
/opt/webapp/bin/webapp: Permission Denied - /opt/webapp/bin/webapp ( Errno:EACCESS)

The issue is the volume is being mounted to the container but from the container it is not having any acces to the mounted volume. I can cd to /opt/webapp/bin but i can not ls /opt/webapp/bin.

Please suggest how it can be fixed. The host mount has all files having 777 permission.

Upvotes: 0

Views: 803

Answers (1)

Behe
Behe

Reputation: 7940

Docker processes have the svirt_lxc_net_t default type. By default these processes are not allowed to access your content in /var, /root and /home.

You have specify a suitable type label for your host folder, to allow the container processes to access the content. You can do this by giving the $PWD/webapp folder the type label svirt_sandbox_file_t.

chcon -Rt svirt_sandbox_file_t $PWD/webapp

After this, you can access the folder from within the container. Read more about it in Dan Walsh's article - Bringing new security features to Docker

Upvotes: 1

Related Questions