Skip to content

Commit

Permalink
Improve docker script (jupyterlab#15241)
Browse files Browse the repository at this point in the history
* Improve docker build cache

* Add port argument
  • Loading branch information
trungleduc authored Oct 10, 2023
1 parent 785b392 commit 2ff6899
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 5 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ RUN if grep -q '^ID=alpine$' /etc/os-release; then \
ENV MAMBA_USER=$NEW_MAMBA_USER
USER $MAMBA_USER


WORKDIR /home/$MAMBA_USER/jupyterlab_cache
COPY --chown=$MAMBA_USER:$MAMBA_USER .. .

RUN micromamba install -n base -c conda-forge git rsync -y && micromamba install -y -n base -f /home/$MAMBA_USER/jupyterlab_cache/binder/environment.yml && micromamba clean --all --yes
COPY --chown=$MAMBA_USER:$MAMBA_USER ../binder/environment.yml ./binder/environment.yml

RUN micromamba install -n base -c conda-forge git rsync -y && micromamba install -y -n base -f ./binder/environment.yml && micromamba clean --all --yes

COPY --chown=$MAMBA_USER:$MAMBA_USER .. .

RUN micromamba run jlpm install

Expand Down
9 changes: 7 additions & 2 deletions docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ GID=$(id -g)
RSYNC_CMD="rsync -ar /home/$DEV_USER/jupyterlab_cache/node_modules/. /home/$DEV_USER/jupyterlab/node_modules"
CMD=$1 # possible command: build, clean, dev, shell

PORT=8888 # Optional, only used for the `dev` command
re='^[0-9]+$'
if [[ $2 =~ $re ]] ; then
PORT=$2
fi

stringmd5() {
echo "md5sum,md5" | tr ',' '\n' | while read -r cmd; do
Expand Down Expand Up @@ -55,13 +60,13 @@ if [[ $CMD == 'build' ]]; then
fi
stop_contaniner
if [[ $CMD == 'dev' || $CMD == '' || $CMD == 'dev-detach' ]]; then
DOCKER_CMD="$RSYNC_CMD && jupyter lab --dev-mode --watch --ip 0.0.0.0"
DOCKER_CMD="$RSYNC_CMD && jupyter lab --dev-mode --extensions-in-dev-mode --watch --ip 0.0.0.0 --port $PORT"
else
DOCKER_CMD="$RSYNC_CMD && bash"
fi
RUN_MODE="-it"
if [[ $CMD == 'dev-detach' ]]; then
RUN_MODE="-d"
fi
docker run $RUN_MODE --name $DEV_CONTAINER --rm -p 8888:8888 -v $ROOT_DIR:/home/$DEV_USER/jupyterlab --entrypoint "/bin/bash" $IMAGE_TAG -i -c "$DOCKER_CMD"
docker run $RUN_MODE --name $DEV_CONTAINER --rm -p $PORT:$PORT -v $ROOT_DIR:/home/$DEV_USER/jupyterlab --entrypoint "/bin/bash" $IMAGE_TAG -i -c "$DOCKER_CMD"
fi
2 changes: 1 addition & 1 deletion docs/source/developer/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ Other available commands:

.. code:: bash
bash docker/start.sh dev # Same as calling bash docker/start.sh
bash docker/start.sh dev 4567 # Start JupyterLab dev container at port 4567
bash docker/start.sh stop # Stop the running container
bash docker/start.sh clean # Remove the docker image
bash docker/start.sh build # Rebuild the docker image
Expand Down

0 comments on commit 2ff6899

Please sign in to comment.