Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Got "permission denied" error at volume mounting directory

I wrote a docker-compose.yml like this:

version: "3"
services:
  notebook:    
    image: jupyter/datascience-notebook
    
    ports:
      - "8888:8888"
    volumes: 
      - jupyterlabPermanent:/hahaha
    environment:
      JUPYTER_ENABLE_LAB: "yes"
      TZ: "Asia/Tokyo"
    command:
      start-notebook.sh --NotebookApp.token=''
volumes:
  jupyterlabPermanent:

Let me make it clear that what characters are appearing on the stage.

  • \hahaha: container side directory which is located at the root directory
  • jupyterlabPermanent: volume which is mounted by hahaha the container side directory.
  • dockerjulia_jupyterlabPermanent\_data: host side directory secured for volume jupyterlabPermanent which syncronize the data located in \hahaha.Full path to dockerjulia_jupyterlabPermanent\_data is \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\dockerjulia_jupyterlabPermanent\_data.

When I use touch command on bash at \hahaha directory, I get permission denied

# bash command line at \hahaha

(base) jovyan@4bcdaa228d9e:/hahaha$ touch test.txt
touch: cannot touch 'test.txt': Permission denied

Because of this, every tasks done in the container cannot be stored in the \hahaha and jupyterlabPermanent volume, and this means data saving is not working in this environment.

How can I solve this? I searched a bit for this, and found I need to change the configuration of permission, but I don't understand it.

I am using Docker Desktop for Windows with WSL 2 on Windows 10 Home.

like image 591
ten Avatar asked Oct 20 '25 10:10

ten


1 Answers

You need root access on the volume to change the permissions. So let's run a plain Ubuntu container and mount the volume

docker run -it --rm -v jupyterlabPermanent:/hahaha ubuntu

now we can change the group ownership to GID 100 which is the group the jovyan user is a member of and also change the permissions to 775 so group members can write to it

chown :100 /hahaha
chmod 775 /hahaha

Now you can exit the Ubuntu container and run the jupyter container and you should be able to write to the volume.

like image 161
Hans Kilian Avatar answered Oct 22 '25 03:10

Hans Kilian