Posts Launch jupyter lab with specific Python Version via docker
Post
Cancel

Launch jupyter lab with specific Python Version via docker

Build jupyter lab image

At first we create a custom jupyter lab docker image. Create a file called Dockerfile and add the following content:

1
2
3
4
5
6
7
8
9
10
11
12
FROM python:3.8

EXPOSE 8888

RUN pip install --no-cache-dir jupyterlab \
    && useradd -ms /bin/bash lab

USER lab

WORKDIR /home/lab

CMD jupyter lab --ip=0.0.0.0

Now using this Dockerfile we build an image with sudo docker build -t jupyter-lab .

Run Image

You can start a jupyter lab instance with sudo docker run -it --name lab -p 8888:8888 -v "/change/local/path:/home/lab" jupyter-lab to which you can normally connect. This will start a container named lab, exposes jupyter lab to your host and mounts /change/local/path. If you want to automatically remove the container after stopping you can additionally add --rm to the command.

When you stopped the container and did not removed it you can restart it with sudo docker start lab -i.

Run /bin/bash

In a second terminal you can connect to the running container with sudo docker exec -it lab /bin/bash. This allows you to run aditional commands like pip install tensorflow.

This post is licensed under CC BY 4.0 by the author.