Skip to content

Reference the pre-built image

Configuration

template-devcontainer maintains a GitHub Actions workflow that publishes Docker images to GitHub Container Registry (GHCR).

The publish is triggered for every push to the main branch, and multiple image tags are created:

  • main uses the default Python version of 3.11
  • main_3.10 uses Python 3.10
  • main_3.12 uses Python 3.12

There are also corresponding tags for the git SHA of the commit on main that triggered the build (e.g. sha, sha_3.10, and sha_3.12).

This makes the pre-built devcontainer image available for use in other projects, potentially decreasing startup and onboarding time even further.

From a devcontainer.json configuration

The pre-built devcontainer image can be used as the basis for another devcontainer.json configuration, similar to how one might reference any other image on Docker Hub or GHCR:

{
  "name": "compilerla/template-devcontainer-pre-built",
  "image": "ghcr.io/compilerla/template-devcontainer:main",
  // initialize pre-commit hooks on attach (assumes .pre-commit-config.yaml)
  "postAttachCommand": "pre-commit install --overwrite"
  // other settings
}

Our devcontainer.pre-built.json shows a minimal example to get a devcontainer running with the same configuration as the normal devcontainer.json, using the pre-built image.

See the full devcontainer.json Reference for details.

Using Docker Compose

In a docker-compose.yml or compose.yml file, you can reference the GHCR image directly in a service definition:

services:
  myservice:
    image: ghcr.io/compilerla/template-devcontainer:main
    volume: ./:/home/compiler/src

Note the volume entry mapping the current directory (with the compose.yml file) into the devcontainer working directory.

And then starting the service with:

docker compose up myservice

This is perhaps a less useful approach, with the default CMD and ENTRYPOINT set in such a way as to make the container essentially hang (useful when attaching from VS Code).