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 directoryjupyterlabPermanent
: volume which is mounted byhahaha
the container side directory.dockerjulia_jupyterlabPermanent_data
: host side directory secured for volumejupyterlabPermanent
which syncronize the data located inhahaha
.Full path todockerjulia_jupyterlabPermanent_data
is\wsl$docker-desktop-dataversion-pack-datacommunitydockervolumesdockerjulia_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.
2
Answers
Thank you for answering my question. The main problem was that I didn't know the existence of the concept of "owner" and "permission" of Linux system. But, an hour of research and learning let me figure out what the problem here is.
My solution 1
My first solution is to try the following command line on Host console:
Adding
-u
option and designating0
, the User ID of root, lets you dive into the container as you areroot
.As I checked using
ll
command at the top directory of the container, the permissions of the files and folders at the top directory of the container appears to be dominated byroot
, and thehahaha
is the one of them.(It meansdocker-compose.yml
createdhahaha
directory for volume at the top directory)Therefore, there was no permission for
jovyan
to touch something athahaha
at the top directory dominated only byroot
, and this is made it by diving into the container asroot
.My solution 2
The second solution is to rewrite the
docker-compose.yml
as follows:This change lets docker-compose create container as volume mounting directory is set at
/home/jovyan/hahaha
. The files and folders under/home/jovyan
is owned and byjovyan
(not byroot
) so jovyan can touch some files at/home/jovyan/hahaha
freely. (No need to dive into the container asroot
)You need root access on the volume to change the permissions. So let’s run a plain Ubuntu container and mount the volume
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
Now you can exit the Ubuntu container and run the jupyter container and you should be able to write to the volume.