Skip to content

Commit 9c832be

Browse files
committed
fix root user issue in docker env
1 parent 718d2fc commit 9c832be

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Dockerfile

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ FROM python:3.6-slim-stretch
22

33
LABEL maintainer="Simon Kassel <[email protected]>"
44

5-
WORKDIR /opt/src/
6-
75
ADD requirements.txt /tmp/requirements.txt
86

97
RUN apt-get update && \
@@ -41,6 +39,17 @@ ENV PYTHONPATH="$PYTHONPATH:/opt/src/"
4139
# Open Ports for Jupyter
4240
EXPOSE 8888
4341

42+
RUN useradd -d /home/user -m -s /bin/bash user && echo "user:user" | chpasswd && adduser user sudo
43+
44+
# start working in the "tester" home directory
45+
WORKDIR /home/user
46+
47+
# Make the files owned by tester
48+
RUN chown -R user:user /home/user
49+
50+
# Switch to your new user in the docker image
51+
USER user
52+
4453
# Run a shell script
4554
CMD ["/bin/bash"]
4655

docker/jupyter

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
# run container
44
docker run -it --rm \
55
-p 8888:8888 \
6-
-v $(pwd $1):/opt/src:rw \
6+
-v $(pwd $1):/home/user:rw \
77
da-project \
8-
jupyter notebook --allow-root --port=8888 --ip=0.0.0.0
8+
jupyter notebook --allow-root --port=8888 --ip=0.0.0.0 --notebook-dir=/home/user/notebooks

docker/run

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
# run container
44
docker run -it --rm \
55
-p 8888:8888 \
6-
-v $(pwd $1):/opt/src:rw \
6+
-v $(pwd $1):/home/user:rw \
77
da-project
88

0 commit comments

Comments
 (0)