Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when mounting volume #17

Closed
ehsueh opened this issue Feb 7, 2017 · 5 comments
Closed

Error when mounting volume #17

ehsueh opened this issue Feb 7, 2017 · 5 comments

Comments

@ehsueh
Copy link

ehsueh commented Feb 7, 2017

Hi again,

I'm experiencing an error when I try to mount a volume for the postgres db by changing the "volumes" section of docker-compose.yml for db to:

volumes: - /absolute/path/to/data/on/host:/var/lib/postgresql/data/:rw

When I try to run docker-compose up db I get:

db_1 | chmod: changing permissions of ‘/var/lib/postgresql/data/’: Operation not permitted

At first I thought maybe it's due to permission or configuration issues on my host machine, so I tried looking into selinux but with no success. When I created a simplified container building from erasche/chado:1.31-jenkins97-pg9.5, I was able to mount a host data directory on /foo and read and write smoothly through /foo to the directory on host. However, if I mount the same host data directory to the same container but on /var/lib/postgresql/data (instead of /foo), the build crashes. 😖

Do you know what might be the problem? What could I try to trace the problem further?

Thank you for your time. 😄

@hexylena
Copy link
Member

hexylena commented Feb 8, 2017

That's quite interesting. Just checking, your docker-compose.yml looks the same as in this repo, except

diff --git a/docker-compose.yml b/docker-compose.yml
index bbe50fd..4057d48 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -30,7 +30,8 @@ services:
         - INSTALL_YEAST_DATA=0
         - PGDATA=/var/lib/postgresql/data/
       volumes:
-        - /var/lib/postgresql/data/
+        - /home/hxr/work/docker-chado/test:/var/lib/postgresql/data/:rw
+        #- /var/lib/postgresql/data/
 
     elasticsearch:
       image: elasticsearch

Or no? With that change even, I can bring up the container without issue.

For a simpler test, this works as well for me.

$ docker run -itP -v /home/hxr/work/docker-chado/test:/var/lib/postgresql/data/:rw erasche/chado:1.31-jenkins97-pg9.5

The chown that's happening is probably https://github.com/docker-library/postgres/blob/master/9.5/docker-entrypoint.sh#L33, are you starting it with --user or anything? Sorry I'm not more help / this is so many bugs.

@ehsueh
Copy link
Author

ehsueh commented Feb 8, 2017

Thanks for getting back to me so quickly.
Yes, my docker-compose.yml looks the same the current one in this repo except for that line. And no, running that simple test (exact command but with different host dir path) gave me the same chmod error 😢 I'm not specifying --user or anything so the user at that point should be root with no permission problem on executing chmod for that dir, right?

@hexylena
Copy link
Member

hexylena commented Feb 8, 2017

so the user at that point should be root with no permission problem on executing chmod for that dir, right?

yes! exactly.

If the simple version fails.. gosh. Maybe the image got updated? docker pull erasche/chado:1.31-jenkins97-pg9.5 if you haven't already tried that?

docker pull erasche/chado:1.31-jenkins97-pg9.5
1.31-jenkins97-pg9.5: Pulling from erasche/chado
Digest: sha256:24b13869f0ac639aefccffd9c49415e76e4e2d03ac8c34ef61c50e38a4dff389

sha256 in case you need to confirm.

Hmm. I'm guessing you found the selinux stuff from here or so docker-library/postgres#116. Does the :z instead of :rw help? (never heard of that one before, no idea how it behaves. Edit: https://docs.docker.com/engine/reference/commandline/run/#/mount-volumes-from-container---volumes-from)

Maybe the other selinux chcon stuff? Or try wiping out the directory and re-running the container? Sorry I'm not able to be more helpful

@ehsueh
Copy link
Author

ehsueh commented Feb 17, 2017

Thanks, Eric.

The image is up to date with sha256.

1.31-jenkins97-pg9.5: Pulling from erasche/chado
Digest: sha256:24b13869f0ac639aefccffd9c49415e76e4e2d03ac8c34ef61c50e38a4dff389
Status: Image is up to date for erasche/chado:1.31-jenkins97-pg9.5

Yes I've tried suggestions from those links. I tried the :z fix again just now. Same error. All the selinux chcon suggestions I found don't seem to solve my error either. I've tried set up a new directory and re-run the whole thing but I still have the same error.

However, I was able to bring up a working instance (with mounted volume) on another box where my user (call it "myhostuser") is a sudo-er. I notice that the data directory on my host changed ownership from "myhostuser.myhostuser" to "guest-c1aswz.myhostuser" with subdirectories written by Postgres with ownership "guest-c1aswz.docker". From my host machine, I needed to use sudo to access, read and write to the modified data directory. (Is this normal?)

I'm still not sure why it doesn't work on that other machine. I'll update you if I find a solution to it. 😄

Thanks again!

@hexylena
Copy link
Member

hexylena commented Feb 21, 2017

Thanks for the update @ehsueh! Interesting, very interesting that you have to be a sudoer. I wonder why that is.

Yes, normal to have to sudo to access the pgdata directory that's volume mounted, the chown inside the container startup usually changes permissions away from the current user (unless remapped with --user).

Please do update if you find out! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants