0

I want to mount folder in Docker container. Using Command Prompt with WSL2. Then, I typed command like...

docker run -it -u $(id -u):$(id -g) -v \C\Users\<username>\Desktop\mounted_folder:/created_in_run <image_id> bash

conditions:
id -u:1000
id -g:1000

In container, I found that created_in_run folder is for user root.(not 1000)

like...(type with ls -la)

drwxr-xr-x 2 root root 4096 Dec 7 05:11 created_in_run

Then I tried to touch test with created_in_run folder.

But, respond is like...

touch: cannot touch 'test': Permission denied

I couldn't find out how to fix this.

Would you please tell me how to solve this matter???

1 Answers1

0
  1. Docker (or containerd) daemon running with root privileges and creating new folder under root user. So created_in_run owned by root
  2. -u $(id -u):$(id -g) means that inside container's user logged in bash is an user with UID → 1000. This parameter do not affect to mounted folder permissions.
  3. Because of your container internal user is non root (because of step ②) and folder mounted with root permissions → UID 1000's user don't have access to it.

How to solve this problem:

Just create created_in_run folder manually before running container and set correct ownership to it:

sudo chown -R 1000:1000 created_in_run

Or change ownership after folder will be created by running command above (You must to change ownership at external folder because docker internal user don't have sudo privileges)

Also you can check related question and solutions here.

rzlvmp
  • 7,512
  • 5
  • 16
  • 45