1

I am creating and starting a container using the Dockerfile and docker-compose.yml files I provided below. My goal is to use Jupyter Notebook on Docker containers. However, when I open the notebook in my browser, it opens in "read-only" mode, which means that any changes I make are not being saved.

Dockerfile

FROM jupyter/tensorflow-notebook
WORKDIR /app
COPY ./notebooks ./notebooks
RUN chmod -R 777 /app

docker-compose.yml

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: tensorf-notebook
    volumes:
      - .:/app
    ports:
      - "8888:8888"
    read_only: false
    command: jupyter notebook --allow-root --ip=0.0.0.0 --port=8888 --NotebookApp.password='sha1:...'

h ttp://localhost:8888/notebooks/notebooks/app.ipynb:

enter image description here

Uğur Eren
  • 163
  • 3
  • 11

1 Answers1

-1

Before changing the permissions, I acquired root access and resolved the issue. I edited the Dockerfile as follows:

Dockerfile:

FROM jupyter/tensorflow-notebook
WORKDIR /app
COPY . .
USER root
RUN chmod -R 777 /app

USER root: Switches the user to root within the container, granting root access.

RUN chmod -R 777 /app: Changes the permissions of the /app directory and its contents to allow read, write, and execute access for all users.

To create a new container by rebuilding the images:

docker compose up -d --build
Uğur Eren
  • 163
  • 3
  • 11
  • `chmod 777` is, to put it delicately, not a best practice and you should not endorse it here. – David Maze May 21 '23 at 10:47
  • What other methods can you suggest then? – Uğur Eren May 21 '23 at 12:16
  • Can you `docker run -u` the container with a numeric user ID that matches the user owning the host directory, or use one of the other approaches from [Docker-compose set user and group on mounted volume](https://stackoverflow.com/questions/40462189/docker-compose-set-user-and-group-on-mounted-volume)? – David Maze May 21 '23 at 12:28
  • 1
    One thing that's not obvious either here or from that question is that the volume mount hides the ownership and permissions of the image directory, so the `RUN chmod 0777` doesn't even have an effect; you could see this with `docker-compose run app ls -ld /app`. The `USER root` is the actual important part of this answer. – David Maze May 21 '23 at 12:29