1

I'm trying to get my Docker container to read and write to a host directory.

I run the container with:

docker run -it -v $(pwd):/file logstash-5.1.2

Inside the container, I can see that /file has the uid of my (non-root) user on the host, and the same permissions as that on the host:

drwxrwxrwx.   2 1156 1156 4096 Jul 21 05:00 file

and that root can't access /file.

root@c642b0c37e09:~# ls /file
ls: cannot open directory /file: Permission denied

I've read posts about creating a user in the container with the same uid as the host, but that seems to be frowned upon.

  1. Why can't root access the directory? I thought it could do everything.
  2. What's the best way to have the container read and write to the mounted directory, which is not owned by root, in Docker?
  3. We're also using Rancher. Does that make it easier? I haven't yet come across something different there, mainly as I'm trying to see if I can do it purely within Docker.
2
  • This could be an issue with SELinux running on the host. Commented Jul 21, 2017 at 7:57
  • I should have mentioned, we're running Red Hat on the host. Commented Jul 21, 2017 at 8:01

1 Answer 1

0

You should change the context as svirt_sandbox_file_t to let container access this folder in this context.

If you are sure about folder permission then just only try;

chcon  -R -t svirt_sandbox_file_t /your/host/path

If are not sure try;

chown  -R groupId:userId /your/host/path
chcon  -R -t svirt_sandbox_file_t /your/host/path

In here chcon command applies the SELinux context with changing the context of "/your/host/path" to the svirt_sandbox_file_t.

Sign up to request clarification or add additional context in comments.

1 Comment

Or use audit2allow to change the contexts for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.