Use Docker in Windows.I want to mount the folder with access privileges.

Asked 1 years ago, Updated 1 years ago, 37 views

I'm trying to use Docker in a Windows environment.

Running the docker command by running WSL2 at the command prompt.

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

I would like to create a created_in_run folder in the container with this command, and create a test file in the created_in_run folder by doing touch test for non-root users in the container.

However, in a Windows environment, id-u is 1000 and id-g is 1000. Even if ls-la is used in the container to check the file owner, the created_in_run folder user will appear as root.

Therefore, even if you do touch test in the created_in_run folder in the container,

touch:cannot touch 'test':permission denied

It doesn't work because it says

The results of the ls-la created_in_run folder are as follows:

 drwxr-xr-x2 root root 4096 Dec 705:11 created_in_run

I've looked into many things, but I don't think I can solve the problem with Docker's permissions in a Windows environment.

By the way, in a Mac environment, users of the created_in_run folder show root when they check with the ls-la command, but it seems that they can do it by touching the created_in_run folder in the container.

In a Mac environment, if you do this again with the ls-la command, the user name will be displayed properly.

Does anyone know how to successfully perform a touch test in the created_in_run folder?

Is there any way to solve this problem?

Thank you for your cooperation.

docker

2022-09-29 21:41

1 Answers

I am writing to let you know that it has been resolved.

First of all, if you want to grant access and use WSL to mount folders on Windows with Docker,

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

must be as shown in .

Access rights are then shared successfully and touch test is now available.

touch test completed

Next, select the folder you want to mount.

/c/Users/'username'/desktop/mounted_folder

In the Windows GUI, you can view it by specifying the path in Explorer as follows:

\wsl$\Ubuntu\c\Users\'username'\desktop\mounted_folder

Explorer Results

I wrote \wsl$\Ubuntu~ because the Linux distribution was Ubuntu.

To verify the default distribution, see

wsl --list-v

You can see it in .
wsl --list-v results

If you want to mount a folder,

/mnt/c/Users/'username'/desktop/mounted_folder

If this is the case, the path to the folder that Explorer can see is

 C:\Users\'username'\Desktop\mounted_folder

will be

This is the folder I want you to mount.

The folder you want to mount is

/c/Users/'username'/Desktop/mounted_folder

If you specified in , and you want to see the folder on the command line, use PowerShell as the command line on Windows.

An error occurs at the command prompt.

command prompt error

Incidentally, when I checked the permissions of the folder, the former case was different from the latter case.
If you specify that the folder to mount is /c/Users/'username'/desktop/mounted_folder
If the folder to mount is /mnt/c/Users/'username'/desktop/mounted_folder

That may be why access rights were not shared with containers.

Incidentally, both id-u and id-g results were the same.
If you specify that the folder to mount is /c/Users/'username'/desktop/mounted_folder
If the folder to mount is /mnt/c/Users/'username'/desktop/mounted_folder

I am not sure why the access rights sharing is not working, but I will share it with you.

That's all I have to report as a resolution.

Thank you for your cooperation.

Thank you for your cooperation.


2022-09-29 21:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.