A Dockerfile is used to build the Docker container where a user’s code will be run. We require one Dockerfile per language version supported.

Dockerfiles are stored in the dockerfiles directory of a challenge repository.

Example

Language Versions

We support multiple versions of a language by creating a Dockerfile for each version.

The name of the Dockerfile should match the language_pack value used in the starter code’s codecrafters.yml file.

For example, for the dockerfile python-3.11.Dockerfile, the relevant section in codecrafters.yml will look something like this:

# Use this to change the Python version used to run your code
# on Codecrafters.
#
# Available versions: python-3.11
language_pack: python-3.11

A language pack usually only specifies the minor version of a language. For example, we support python-3.11 and python-3.12 but not python-3.11.1.

Dockerfile Structure

  • Where available, use the official Docker image for the language.
  • Where available, use an image based on alpine to reduce the size of the image.
  • A Dockerfile must install all dependencies required to run the user’s code.
    • It must copy in the minimal set of files from the user’s code required to install dependencies. For example, for Rust this’d be Cargo.toml and Cargo.lock.
    • It must then run the dependency installation command. For example, for Rust this’d be cargo build --release.
  • The files required to build dependencies must be stored as CSV in the CODECRAFTERS_DEPENDENCY_FILE_PATHS environment variable, so that CodeCrafters can detect changes in them and trigger a rebuild when needed.
  • A Dockerfile must only copy in the User’s code as the last step. This allows us to share the cached layers between different users.
  • The resulting image should conform to the Test Runner Image Interface.