Can I change the ownership of the directory installed on the volume in IBM containers?

I am trying to run postgres in IBM containers. I just created a volume:

$ cf ic volume create pgdata 

Then install it:

 $ cf ic run --volume pgdata:/var/pgsql -p 22 registry.ng.bluemix.net/ruimo/pgsql944-cli 

After entering the container via ssh, I found that the mounted directory belongs to root:

 drwxr-xr-x 3 root root 4096 Jul 8 08:20 pgsql 

Since postgres does not allow root to run, I want to change the ownership of this directory. But I can’t change the ownership of this directory:

 # chown postgres:postgres pgsql chown: changing ownership of 'pgsql': Permission denied 

Can I change the ownership of a mounted directory?

+8
containers ibm-cloud
source share
3 answers

In IBM Containers, the user namespace is included for the docker engine. When the user namespace is turned on, the effective root inside the container is the non-root party, the container process, and NFS does not allow the non-root user to perform the chown operation on the volume inside the container. Note that the pgdata volume is NFS, this can be verified by running mount -t nfs4 from the container.

You can try the workaround suggested for How can I fix permissions using docker on a bluemix volume?

In this case, it will be

 1. Mount the Volume to `/mnt/pgdata` inside the container cf ic run --volume pgdata:/mnt/pgdata -p 22 registry.ng.bluemix.net/ruimo/pgsql944-cli 2. Inside the container 2.1 Create "postgres" group and user groupadd --gid 1010 postgres useradd --uid 1010 --gid 1010 -m --shell /bin/bash postgres 2.2 Add the user to group "root" adduser postgres root chmod 775 /mnt/pgdata 2.3 Create pgsql directory under bind-mount volume su -c "mkdir -p /mnt/pgdata/pgsql" postgres ln -sf /mnt/pgdata/pgsql /var/pgsql 2.2 Remove the user from group "root" deluser postgres root chmod 755 /mnt/pgdata 
+7
source share

In your Dockerfile, you can change directory permissions.

RUN chown postgres:postgres pgsql

Also, if you use ssh, you can change directory permissions using sudo . sudo chown postgres:postgres pgsql

0
source share

All Articles