Dockerfile for PyCaret

In this post, we will learn how to build a docker container for PyCaret.

We create a docker image from a Dockerfile. And, we will see how to build a docker container and run a jupyterlab.

Dockerfile

The entire contents of the Dockerfile are as follows.

FROM python:3.8

WORKDIR /opt
RUN pip install --upgrade pip
RUN pip install pycaret \
				jupyterlab 
RUN pip install lux-api
RUN jupyter nbextension install --py luxwidget
RUN jupyter nbextension enable --py luxwidget
WORKDIR /work

CMD ["jupyter","lab","--ip=0.0.0.0","--allow-root","--LabApp.token=''"]

We create the docker image based on the python image, whose version is 3.8.

By the sentence “WORKDIR /opt”, we specify the directory for installing the python libraries.

And, we upgrade pip, to install the external python libraries in order. Here, we install pycaret and jupyterlab. Of course, you can also install other libraries.

Note that the last sentence ‘WORKDIR /work’ indicates that the current directory is set at ‘/work/’ after we enter the docker container.

Build a Dockerfile

Let’s create a docker image from the Dockerfile. Execute the following command in the directory where the Dockerfile exists.

$ docker build .

After building the docker image, you can confirm the result by the following command. Later, we will use the ‘IMAGE ID’.

$ docker images

Run a docker container

Here, we run the docker container from the above docker image. The command format is as follows.

$ docker run -it -p 8888:8888 -v ~/mounted_to_docker/:/work (IMAGE ID)
'-p 8888:8888': 
-> Allows the port, whose number is 8888, in a docker container

'-v ~/mounted_to_docker/:/work': 
->Synchronizes the local directory you specified('~/mounted_to_docker/') with the directory in the container('/work').

When the docker container was successfully running, you can access a jupyterlab in your web browser. The URL appears in your terminal.

Your local directory ‘~/mounted_to_docker/’ is mounted to the working directory ‘/work’ in the container.

Congratulation!! You have prepared the environment for PyCaret.