Give write permission to docker container

4.2k Views Asked by At

I'm running lamp container. So from my app running on apache server I need to upload a file. I keep getting an error: The upload destination folder does not appear to be writable. So, I need to give permission to the folder located in /Documents/Kitematic/lamp/app/appv2/uploads to be written... How can I do that? I already tried "mkdir 077 directory" but is not working. Following you can see all my permissions:

 # ls -al
 total 96
 drwxr-xr-x   1 root     root  4096 Sep 16 10:45 .
 drwxr-xr-x   1 root     root  4096 Sep 16 10:45 ..
 drwxr-xr-x   2 root     root  4096 Sep 16 10:45 0777
 drwxr-xr-x   9 www-data staff  306 Sep 16 09:06 app
 drwxr-xr-x   1 root     root  4096 Aug 16  2018 bd_build
 drwxr-xr-x   1 root     root  4096 Jun 12 19:16 bin
 drwxr-xr-x   2 root     root  4096 Apr 24  2018 boot
 -rwxr-xr-x   1 root     root  2049 Jun 12 19:13 create_mysql_users.sh
 drwxr-xr-x   5 root     root   360 Sep 16 13:16 dev
 -rwxr-xr-x   1 root     root     0 Sep 16 09:11 .dockerenv
 drwxr-xr-x   1 root     root  4096 Sep 16 09:11 etc
 drwxr-xr-x   2 root     root  4096 Apr 24  2018 home
 drwxr-xr-x   1 root     root  4096 Jul 24  2018 lib
 drwxr-xr-x   2 root     root  4096 Jul 24  2018 lib64
 drwxr-xr-x   2 root     root  4096 Jul 24  2018 media
 drwxr-xr-x   2 root     root  4096 Jul 24  2018 mnt
 drwxr-xr-x   2 root     root  4096 Jul 24  2018 opt
 dr-xr-xr-x 194 root     root     0 Sep 16 13:16 proc
 drwx------   1 root     root  4096 Jun 12 19:18 root
 drwxr-xr-x   1 root     root  4096 Sep 16 13:16 run
 -rwxr-xr-x   1 root     root  2160 Jun 12 19:13 run.sh
 drwxr-xr-x   1 root     root  4096 Jun 12 19:16 sbin
 drwxr-xr-x   2 root     root  4096 Jul 24  2018 srv
 -rwxr-xr-x   1 root     root    67 Jun 12 19:13 start-apache2.sh
 -rwxr-xr-x   1 root     root    29 Jun 12 19:13 start-mysqld.sh
 dr-xr-xr-x  13 root     root     0 Sep 16 13:16 sys
 drwxrwxrwt   1 root     root  4096 Sep 16 13:18 tmp
 drwxr-xr-x   1 root     root  4096 Jul 24  2018 usr
 drwxr-xr-x   1 root     root  4096 Jun 12 19:17 var
1

There are 1 best solutions below

10
Majid Rehman On

Use ls -al inside the container to see the current permissions. Use id to see the current uid.

With docker exec you can pass a flag to change the current user. And to change permissions, you can use chmod to change the permissions themselves, chown to change the user ownership.

e.g

docker exec -u root container_1 chmod 777 .

This command will allow any user to read or write to the current folder inside the container by running as the root.