container: volume dockerfile does not work

Viewed 101

I m not able to launch new jupyter-notebook from my project.

Below my dockerfile.

FROM python:3.9.0
ARG WORK_DIR=/opt/dir1
RUN apt-get update && apt-get install cron -y && apt-get install -y default-jre
# Install python libraries
COPY requirements.txt /tmp/requirements.txt
RUN pip install --upgrade pip && pip install -r /tmp/requirements.txt
WORKDIR $WORK_DIR
EXPOSE 8888
# Copy etl code
# copy code on container under your workdir "/opt/dir1"
COPY . .
ENTRYPOINT ["sh", "-c"]
CMD ["jupyter-notebook --ip 0.0.0.0 --no-browser --allow-root]    
VOLUME /home/data/dir1/

then in my terminal i did

#build
docker build -t my-python-app .
#run
docker run -it -p 8888:8888 my-python-app
#in container i did
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root 

I think that my VOLUME doesn't work because when i did modifications in file of container nothing happens in the host /home/data/dir1/.

Does anyone knows why and how to solve it?

2 Answers

You can use, docker run -it /bin/bash (image name) and try to navigate to the folder you have set the volume to, and see if an error occurs and check permissions.

When using volumes, check on the host system you can access the folder. Afterwards check which user you are, Docker allows to parse your USER_ID and GROUP_ID to the container.

From there you can use the same user and group as you are on the host system. If you wanted to access the same folder on the host system, you can enter into permissions problems.

More information on this on the following webpage. https://jtreminio.com/blog/running-docker-containers-as-current-host-user/

Maybe it's could be help you : try another way to start the volume inside container, for example add it within "run" command container creation. i've working with docker and i've never added volumes in this way (this doesn't mean you way is wrong)

Here two examples to working with volumens,I recommend you second link.

docker official docs , working with volumes example

Related