Files
coder/examples/templates/devcontainer-docker
Cian Johnston 005254d64a chore(examples): update sample devcontainer templates (#13796)
Updates docker and kubernetes devcontainer templates

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2024-07-22 14:10:02 +01:00
..

display_name, description, icon, maintainer_github, verified, tags
display_name description icon maintainer_github verified tags
Devcontainers (Docker) Provision envbuilder containers as Coder workspaces ../../../site/static/icon/docker.png coder true
container
docker
devcontainer

Remote Development on Docker Containers (with Devcontainers)

Provision Devcontainers as Coder workspaces in Docker with this example template.

Prerequisites

Infrastructure

Coder must have access to a running Docker socket, and the coder user must be a member of the docker group:

# Add coder user to Docker group
sudo usermod -aG docker coder

# Restart Coder server
sudo systemctl restart coder

# Test Docker
sudo -u coder docker ps

Architecture

Coder supports Devcontainers via envbuilder, an open source project. Read more about this in Coder's documentation.

This template provisions the following resources:

  • Docker image (persistent)
  • Docker container (ephemeral)
  • Docker volume (persistent on /workspaces)

with envbuilder. The Git repository is cloned inside the /workspaces volume if not present. Any local changes to the Devcontainer files inside the volume will be applied when you restart the workspace. Keep in mind that any tools or files outside of /workspaces or not added as part of the Devcontainer specification are not persisted. Edit the devcontainer.json instead!

Note

This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.

Docker-in-Docker

See the Envbuilder documentation for information on running Docker containers inside a devcontainer built by Envbuilder.

Caching

To speed up your builds, you can use a container registry as a cache. When creating the template, set the parameter cache_repo.

For example, you can run a local registry:

docker run --detach \
  --volume registry-cache:/var/lib/registry \
  --publish 5000:5000 \
  --name registry-cache \
  --net=host \
  registry:2

Then, when creating the template, enter localhost:5000/devcontainer-cache for the parameter cache_repo.

[!NOTE] We recommend using a registry cache with authentication enabled. To allow Envbuilder to authenticate with the registry cache, specify the variable cache_repo_docker_config_path with the path to a Docker config .json on disk containing valid credentials for the registry.