Docker Community Forums

Share and learn in the Docker community.

How to share ownership of mounted directory on docker?

Hi I am still new at using docker and also still learning using ubuntu. Currently I am planning to do a machine learning training on a supercomputer shared by many user. I have successfully created an image and mount all the necessary data but when I try to run the training, I got permission denied when the code tries to access a .txt file. Here is the error

user@701c214f9fa9:/app/sfsnet$ python main_mix_training.py
Traceback (most recent call last):
  File "main_mix_training.py", line 156, in <module>
    main()
  File "main_mix_training.py", line 132, in main
    with open(args.log_dir+'/details.txt', 'w') as f:
PermissionError: [Errno 13] Permission denied: './results//details.txt'
user@701c214f9fa9:/app/sfsnet$ python main_mix_training.py
Traceback (most recent call last):
  File "main_mix_training.py", line 156, in <module>
    main()
  File "main_mix_training.py", line 132, in main
    with open(args.log_dir+'/details.txt', 'w') as f:
PermissionError: [Errno 13] Permission denied: './results//details.txt'

I have checked the mounted directory ownership and it should all be mine (dgx_user6) :

total 308
-rw-r--r-- 1 dgx_user6 dgx_user6  1271  二  14 05:32  checkmodel.py
-rw-r--r-- 1 dgx_user6 dgx_user6   458  二  13 23:51  cropping.py
-rw-r--r-- 1 dgx_user6 dgx_user6 12890  二  14 14:03  data_loading.py
drwxr-xr-x 5 dgx_user6 dgx_user6  4096  二  14 04:26  dataset
-rw-r--r-- 1 dgx_user6 dgx_user6   641  二  13 23:51  generate_dataset_csv.py
-rw-r--r-- 1 dgx_user6 dgx_user6  2687  二  13 23:51  interpolate.py
-rw-r--r-- 1 dgx_user6 dgx_user6    95  二  14 05:32  interpolate.sh
-rw-r--r-- 1 dgx_user6 dgx_user6     0  二  14 05:32  log_file
-rw-r--r-- 1 dgx_user6 dgx_user6  6555  二  13 23:51  main_gen_pseudo-data.py
-rw-r--r-- 1 dgx_user6 dgx_user6  7548  二  13 23:51  main_gen_synthetic_and_full.py
-rw-r--r-- 1 dgx_user6 dgx_user6  7030  二  14 14:12  main_mix_training.py
-rw-r--r-- 1 dgx_user6 dgx_user6 69169  二  14 05:34 'model backup.py'
-rw-r--r-- 1 dgx_user6 dgx_user6  2914  二  14 05:32  model_loading_synchronization.ipynb
-rw-r--r-- 1 dgx_user6 dgx_user6 69339  二  14 05:34  models.py
drwxr-xr-x 2 dgx_user6 dgx_user6  4096  二  13 23:51  pretrained
drwxr-xr-x 2 dgx_user6 dgx_user6  4096  二  14 05:33  __pycache__
-rw-r--r-- 1 dgx_user6 dgx_user6  3490  二  13 23:51  README.md
drwxr-xr-x 9 dgx_user6 dgx_user6  4096  二  14 05:33  results
-rw-r--r-- 1 dgx_user6 dgx_user6  5090  二  14 05:34  shading.py
-rw-r--r-- 1 dgx_user6 dgx_user6   605  二  14 05:34  super_resolution.py
-rw-r--r-- 1 dgx_user6 dgx_user6 39867  二  14 05:32 'train backup.py'
-rw-r--r-- 1 dgx_user6 dgx_user6 32377  二  13 23:51  train.py
-rw-r--r-- 1 dgx_user6 dgx_user6  1685  二  13 23:51  utils.py

When I check the folder ownership via container I got this ID instead

drwxr-xr-x 8 1007 1007 4096 Feb 14 06:12 .

I created the container using this command

nvidia-docker run -e NVIDIA_VISIBLE_DEVICES=3 -t -i --name coba --mount type=bind,src=/home/dgx_user6/SfSNet/,dst=/app/sfsnet sfs_face

I tried to change the ownership via chown command inside the container but got permission is denied, maybe someone can help me resolve this problem

This is the ID of user and group dgx_user6. You see the numbers because they don’t exist in the container. Your file and folders are writable only by dgx_user6 (0644 and 0755) and the container runs under another user. In the error you see that the application tries to write into folder results, so you have to make at least this one writable by anyone. And you have to to this on the host (where you are the owner), not in the container (where you are probably user with ID 1000).