You are not logged in.

#1 2016-03-04 13:23:42

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

[SOLVED]Docker rprivate mount propagation problem - how to change ?

Hi,

I am trying to configure several docker containers and I have problems using volumes. I fail to understand how to create shared folder between my host and my containers.

I tried to ask for help on github (https://github.com/docker/docker/issues/20876) or reddit but nobody replied.

Basically, I use a docker-compose file to create containers for postgresql, sonarqube and gocd-server for the moment. I mount volumes and my host cannot change what's inside the volume in the container and vice versa. I can see that my containers write on my host because files are created but if I change those files on my host, those changes are not reflected in my container.

When I run a docker inspect, I can see that the Propagation is rprivate in the mount flags but I don't know how to change that.

I tried to add the following in my docker.service but no success :
ExecStartPre=/bin/mount --make-rshared /

my folders are on my disk /dev/sdb1 (/mnt/data), I also tried with /mnt/data and not / but this didn't change anything.

Does anybody here know how to change the propagation flags from rprivate to rshared ? Apparently, rshared allows the host and the container to have the same visibility for their shared folders.

Thanks.

Last edited by hiveNzin0 (2016-03-07 07:45:27)

Offline

#2 2016-03-04 15:58:03

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED]Docker rprivate mount propagation problem - how to change ?

Can you show the exact commands you are using to start the container (simple case that reproduces your results). Normally something like

docker run -it -v $(pwd):/mnt ubuntu bash

Will mount your current working directory to /mnt in the container and you can make changes out outside or inside the container. The catch is regular Linux file system permissions. You have to try to match permissions between the container and host. I've never heard of anyone having to deal with rprivate before.

Scott

Edit: you can also try to ask cpuguy83 in #docker on IRC.

Last edited by firecat53 (2016-03-04 16:01:00)

Offline

#3 2016-03-04 16:23:36

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

Re: [SOLVED]Docker rprivate mount propagation problem - how to change ?

Hi,

that's really weird, this works as expected.

There must be something weird with docker compose.

I am going to try to run my gocd-server images manually and see.

Thanks.

Offline

#4 2016-03-05 18:09:11

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

Re: [SOLVED]Docker rprivate mount propagation problem - how to change ?

edit : well, it's not working as expected.

If I run this command :

docker run -it -v /mnt/data/docker/gocd/ssh:/var/go/.ssh gocd-server-test bash

it works, I can act on the shared folder and see the changes in my host and my container.

If I start a container like this

docker run -d -p 8153:8153 -v /mnt/data/docker/gocd/ssh:/var/go/.ssh gocd-server-test

I don't see the changes on my host from the container.

There must be something really wrong about my understanding of volumes, I am going to read again the documentation.

Thanks anyway.

Last edited by hiveNzin0 (2016-03-05 18:17:35)

Offline

#5 2016-03-05 18:36:20

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED]Docker rprivate mount propagation problem - how to change ?

I'm still wondering if there's a permissions problem. I'm not familiar with the gocd-server, but you have specific code examples of what steps you are doing, I'd be happy to try and reproduce it on this end.

Scott

Offline

#6 2016-03-05 19:13:17

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

Re: [SOLVED]Docker rprivate mount propagation problem - how to change ?

Thanks a lot.

For information, I first started using the official gocd-server (https://hub.docker.com/r/gocd/gocd-server/) but the UID/GID for the user "go" inside the container was 999. On my arch host, a user already had that uid/gid (systemd-journal-something) so I couldn't use that image. That's why I created my own docker image with uid/gid 15000 to be sure it is not used.

Here is what I do :

1) copy the file in a directory and go in it that directory : http://pastebin.com/yLq2CpfN

2) create the image with the following command :
docker build -f Dockerfile -t gocd-server-test .

3) create user "go" with uid 15000 and group "go" with gid 15000
This user is needed in the container because the pull from git repository is done by this user. If my user "go" on my host and container both have the same uid/gid, they have the same rights to manage the same directory on the host and the containers.
Normally, root is fine but since the user "go" is required in the container, root doesn't work

4) now that the gocd-server-test is created, I can use a docker-compose file to create what I need

a) create a directory docker

gocd-server:
  container_name: gocd-server
  image: gocd-server-test
  ports:
    - "18153:8153"
    - "18154:8154"
  volumes:
    - /mnt/data/docker/gocd/db:/var/lib/go-server/db/h2db
    - /mnt/data/docker/gocd/plugins:/var/lib/go-server/plugins/external
    - /mnt/data/docker/gocd/flyweight:/var/lib/go-server/pipelines/flyweight
    - /mnt/data/docker/gocd/config:/etc/go
    - /mnt/data/docker/gocd/ssh:/var/go/.ssh
    - /mnt/data/docker/gocd/artifacts:/var/lib/go-server/artifacts

5) so normally now, I have a folder name docker in /mnt/data and this folder contains my docker-compose.yml and postgres_env
In a terminal, I go to the directory /mnt/data/docker and run

docker-compose -up -d

This starts all the images.

6) now the problems are there
if I create a file in /mnt/data/docker/gocd/ssh on my host, the file is not displayed in my container
If I create a file in /var/go/.ssh inside my container, the file is not displayed on my host

a) [20:08:39 - gillouche@arch:~/data/docker/gocd/ssh]$ ls -l
total 0
-rw-r--r-- 1 root root 0 Mar  5 19:07 testcontainer.txt
-rw-r--r-- 1 root root 0 Mar  5 19:14 testhost2.txt
-rw-r--r-- 1 root root 0 Mar  5 19:04 testhost.txt

b) docker run -ti gocd-server-test bash
c) inside the container :
root@6fb0847e1a5a:/var/go/.ssh# ls -al /var/go/.ssh
total 0
drwxr-xr-x 2 go go  6 Mar  5 17:59 .
drwxr-xr-x 3 go go 18 Mar  5 17:59 ..
root@6fb0847e1a5a:/var/go/.ssh#

I must do something wrong but I don't know what yet. I was told on reddit that it was because I used relative path like ./gocd in the docker-compose file but even with absolute path, I have the problem.

Or somebody said this on github

Since all the host volume path in your docker compose start with ./ the host directory is mounted instead of a named volume being used.

My docker-compose understanding is still limited unfortunately, so I'll give you a bit more details from a straight docker engine usage.

Any changes you make to the container outside of those bind mounts should stay within the container though, you would only lose them if you were to use --rm as part of your docker run if not, upon a subsequent docker start everything should still be there.

I don't mind the tools I use, normal docker or docker-compose. I am just trying to have a working environment with a working setup that I can transfer to my synology NAS .

Thanks.

edit : I first heard of docker-compose file with this tutorial : https://realpython.com/blog/python/djan … d-machine/

Last edited by hiveNzin0 (2016-03-05 19:17:48)

Offline

#7 2016-03-06 20:39:59

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED]Docker rprivate mount propagation problem - how to change ?

Tested and works fine here with docker-compose. Built the gocd-server-test image, created the docker-compose.yml file, created user and group 'go', created the data directories and 'chown -R go:go <path/to/data>'. Maybe that's the step you forgot? Ran the container with 'docker-compose up' and then did a 'docker exec -it gocd-server bash' and created/deleted files from inside the container while watching that folder from the host and vice versa.

Scott

Last edited by firecat53 (2016-03-06 20:40:26)

Offline

#8 2016-03-07 07:45:10

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

Re: [SOLVED]Docker rprivate mount propagation problem - how to change ?

Thanks for the effort smile

I could make everything work as I would expected.

If I run this : "docker exec -it gocd-server bash", I don't see the mounted folder from host inside, I need to add the arguments -v .../ssh:/var/go/.ssh to be able to change the folder inside the container.

I still need to read a lot about containers I think but I'll understand  everything at some point.

Thanks again.

Offline

Board footer

Powered by FluxBB