Skip to content

Commit 117840c

Browse files
committed
refactor(docker): make jupyter user configurable and add sudo support
- Replace hardcoded 'jovyan' user with configurable JUPYTER_USER - Add sudo installation and permissions for the new user - Update volume paths to use the configurable username - Remove unnecessary environment variables
1 parent 4639bcb commit 117840c

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

Dockerfile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ USER root
55

66
# Install git
77
RUN apt-get update && \
8-
apt-get install -y git && \
8+
apt-get install -y git sudo && \
99
git config --system credential.helper 'store --file ~/.git-credentials' && \
1010
rm -rf /var/lib/apt/lists/*
1111

12-
# Switch back to jovyan user and install extensions
13-
USER jovyan
14-
COPY --chown=jovyan:users requirements.txt /tmp/
15-
RUN pip install --no-cache-dir -r /tmp/requirements.txt
12+
# Create user and grant sudo
13+
ARG JUPYTER_USER=jupyter_user
14+
RUN useradd -m -s /bin/bash -N -g users ${JUPYTER_USER} && \
15+
chmod 0440 /etc/sudoers.d/jovyan && \
16+
echo "${JUPYTER_USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/${JUPYTER_USER}
17+
18+
# Install extensions
19+
COPY --chown=${JUPYTER_USER}:users requirements.txt /tmp/
20+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
21+
22+
# Switch to user
23+
USER ${JUPYTER_USER}
24+
WORKDIR /home/${JUPYTER_USER}

docker-compose.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ services:
44
context: .
55
args:
66
JUPYTER_IMAGE_VERSION: latest
7+
JUPYTER_USER: ${JUPYTER_USER:-jupyter_user}
78
ports:
89
- "8888:8888"
910
volumes:
10-
- ./data:/home/jovyan/work
11+
- ./data:/home/${JUPYTER_USER:-jupyter_user}/work
1112
environment:
12-
- JUPYTER_ENABLE_LAB=yes
13-
- GRANT_SUDO=yes
14-
user: jovyan
13+
- JUPYTER_ENABLE_LAB=yes

0 commit comments

Comments
 (0)