Tutorial
Getting started with Docker

Getting started with Docker

Docker is available for Devboxes and Repositories. With Docker, you can get root access and install any package to use within CodeSandbox, including databases and new languages.

Here (opens in a new tab) you can find a sandbox that uses Docker.

1. Create a Dockerfile

To get started with Docker, you need to create a new file called devcontainer.json inside the .devcontainer folder. As an example, you could put these contents in:

.devcontainer/devcontainer.json
{
    "build": { "dockerfile": "Dockerfile" },
}

And then create a Dockerfile in the same devcontainer folder:

.devcontainer/Dockerfile
FROM ubuntu
 
# Install htop by default
RUN apt update -y && apt install -y htop
💡

This Dockerfile is intended for development, not for deployment. This means that you probably don't need to COPY or ADD. We handle that for you by mounting the project directory at /workspace in the container.

💡

At this time, CodeSandbox currently only supports Debian and Ubuntu based images, for the best compatibility and user experience.

2. Rebuild the container

Now that you've created a Dockerfile and saved it, you should see a notification pop up, asking you to rebuild the container. Whenever the Dockerfile changes, we need to rebuild the container from that Dockerfile.

Notification for rebuilding the container