thacoon's Blog

Launch jupyter lab with specific Python Version via docker

· thacoon

Build jupyter lab image

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

 1FROM python:3.8
 2
 3EXPOSE 8888
 4
 5RUN pip install --no-cache-dir jupyterlab \
 6    && useradd -ms /bin/bash lab
 7
 8USER lab
 9
10WORKDIR /home/lab
11
12CMD 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.

#python

Reply to this post by email ↪