--- title: Docker Deployment description: How to deploy Python notebooks as Mercury web applications using Docker containers --- import { Code } from '@astrojs/starlight/components'; import { Aside } from '@astrojs/starlight/components'; 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. ## Create a Dockerfile 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`. ## Docker commands Below are the most common Docker commands you will need when working with the Mercury container. ### Build the Docker image Build the Docker image from the `Dockerfile` and tag it as `mercury-server`: ```bash docker build -t mercury-server . ```` This command only needs to be run again if you change the Dockerfile code. ### Run the container (foreground mode) This mode is useful during development. The container runs in the foreground and is automatically removed when you stop it. ```bash 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 ``` ### Run the container (background mode) For longer-running sessions or server-like usage, run Mercury in detached mode by adding `-d` flag: ```bash 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. ### View container logs To inspect Mercury logs or verify that the server started correctly: ```bash docker logs -f mercury-server ``` Press Ctrl + C to stop following the logs. ### Open a shell inside the container (debugging) If you need to inspect the container environment or verify mounted files: ```bash docker exec -it mercury-server /bin/sh ``` For example, you can list mounted notebooks: ```bash ls -la /workspace ``` ### Stop the container If Mercury is running in background mode, stop it with: ```bash docker stop mercury-server ``` ### Stop and remove the container To stop and remove the container in a single command: ```bash docker rm -f mercury-server ```