Skip to content

Docker Deployment

This guide explains how to run Mercury as a web application using Docker.
Docker allows you to package Mercury together with Python and all dependencies, making deployment predictable and reproducible across different machines.

Start by creating a file named Dockerfile in your project directory.

The following Dockerfile uses a lightweight Python image, installs Mercury, and starts the Mercury server on port 8888.

Dockerfile
FROM python:3.12-slim
# Install Mercury
RUN pip install mercury==3.0.0a2
# You can also install needed packages here,
# For example install pandas
# RUN pip install pandas
# Directory where notebooks will be mounted
WORKDIR /workspace
# Mercury default port
EXPOSE 8888
# Start Mercury server
CMD ["mercury", "--ip=0.0.0.0", "--no-browser", "--allow-root"]

Below are the most common Docker commands you will need when working with the Mercury container.

Build the Docker image from the Dockerfile and tag it as mercury-server:

Terminal window
docker build -t mercury-server .

This command only needs to be run again if you change the Dockerfile code.

This mode is useful during development. The container runs in the foreground and is automatically removed when you stop it.

Terminal window
docker run --rm -it \
-p 8888:8888 \
-v /my/directory/with/notebooks:/workspace \
mercury-server

After starting, open your browser and navigate to:

http://localhost:8888

For longer-running sessions or server-like usage, run Mercury in detached mode by adding -d flag:

Terminal window
docker run -d --name mercury-server \
-p 8888:8888 \
-v /my/directory/with/notebooks:/workspace \
mercury-server

The container will continue running in the background until you stop it explicitly.

To inspect Mercury logs or verify that the server started correctly:

Terminal window
docker logs -f mercury-server

Press Ctrl + C to stop following the logs.

Open a shell inside the container (debugging)

Section titled “Open a shell inside the container (debugging)”

If you need to inspect the container environment or verify mounted files:

Terminal window
docker exec -it mercury-server /bin/sh

For example, you can list mounted notebooks:

Terminal window
ls -la /workspace

If Mercury is running in background mode, stop it with:

Terminal window
docker stop mercury-server

To stop and remove the container in a single command:

Terminal window
docker rm -f mercury-server