# Devcontainer workstations

> For the complete documentation index, see [llms.txt](https://docs.ringleader.dev/llms.txt).


> Ringleader can run a repository's own devcontainer.json on a workstation, so you don't have to rewrite an environment your team already maintains.


Ringleader can run a repository's own `devcontainer.json` on a workstation, so you don't
have to rewrite an environment your team already maintains.

Many repositories describe
their development environment in `devcontainer.json`, the format VS Code, GitHub
Codespaces and most other development-environment tools read. You attach the repository to
a workstation as a code source and set one flag. The workstation clones the code, builds
the devcontainer, and puts your shell inside it. Ringleader runs the file with the
reference `devcontainer` command-line tool. It adds what the format has no words for: the
workstation itself, its lifecycle, where it runs, and who can reach it. To set one up step by
step, follow [Run a repository's devcontainer](https://docs.ringleader.dev/guides/run-devcontainer/).

## Devcontainer declaration

A devcontainer belongs to a checkout, so you declare it on the
[code source](https://docs.ringleader.dev/workstations/packages-tools-settings/code-dotfiles-trusted-folders/#code-sources)
that holds the repository. Only one source on a workstation can run a devcontainer.
Declaring one does three things:

- The source's `path` becomes the workspace folder. Ringleader mounts the checkout into the
  container there, as the format expects. A source with no `path` is refused.
- The [`docker`](https://docs.ringleader.dev/reference/tools/devtools/docker/) and
  [`devcontainer-cli`](https://docs.ringleader.dev/reference/tools/devtools/devcontainer-cli/) devtools are
  added for you. Declare one yourself only to choose its version.
- Ringleader adds a service named `devcontainer`, which runs `devcontainer up` with a
  readiness check, and allows it a start time long enough for an image build.

## Devcontainer shell and file locations

The workstation is a virtual machine, and the devcontainer runs inside it on Docker. Your
tools land in the container by default, because that is the environment you asked for:

| You use | It lands |
|---|---|
| `rl shell`, `ssh <workstation>`, VS Code Remote SSH, JetBrains Gateway | inside the container, as the file's `remoteUser` |
| `rl shell --script`, `rl file cp` | inside the container |
| `rl shell --host`, `rl file cp --host` | on the virtual machine |
| `scp`, `sftp` | on the virtual machine |

`scp` and `sftp` use SSH's file-transfer subsystem (SFTP), which doesn't go through the
login shell. So they land on the virtual machine, while `rsync` and `rl file cp` land in the
container. For the
workspace this rarely matters: the checkout is mounted, so a file under the source's `path`
is the same file either way. It matters only for paths outside the workspace folder.

Every devcontainer workstation also gets a second login user, `<user>-host`, so login user
`dev` gets `dev-host`. Its shell is an ordinary shell on the virtual machine, and it accepts
the same SSH keys.

<div class="callout callout-tip">
  <p class="callout-title">Repair with the host login</p>
  <div class="callout-body">
    Use the <code>&lt;user&gt;-host</code> login to repair a workstation whose container failed to build, or to
point an editor at the virtual machine instead of the container.
  </div>
</div>


`rl shell` has one way to run a command on the virtual machine: `--host`. With `ssh`, start
the remote command with `run-on-host`, as in `ssh <workstation> run-on-host uptime`.
`rl shell <workstation> -- run-on-host uptime` runs in the container.

To run a command on the virtual machine step by step, follow
[Run a command on the virtual machine](https://docs.ringleader.dev/guides/run-devcontainer/#run-a-command-on-the-virtual-machine).
To repair a build, follow
[Repair a failed build](https://docs.ringleader.dev/guides/run-devcontainer/#repair-a-failed-build).

## Devcontainer readiness

A devcontainer workstation reaches `Configured`, its
[condition](https://docs.ringleader.dev/reference/resources/workstation/#conditions-and-their-reasons) for an
applied configuration, once `devcontainer up` succeeds and the container passes its
readiness check. A devcontainer that fails to build blocks
`Configured` like any other failed step. The workstation reports the failing step,
`rl troubleshoot` has its output, and the `<user>-host` account still works.

On a fresh workstation with a heavyweight devcontainer, the first build takes minutes, not
seconds. `devcontainer up` pulls the base image, builds a layer for each Feature, and runs
the file's lifecycle commands.

## Devcontainer ports

The container's ports are published to the virtual machine. To reach one from your computer,
declare a forward with `ports` or a [LocalBinding](https://docs.ringleader.dev/reference/resources/localbinding/), as on any other
workstation. Nothing inside the container is forwarded to your computer on its own,
including the ports the file lists in `forwardPorts`. [Port and socket forwarding](https://docs.ringleader.dev/workstations/connectivity/port-socket-forwarding/)
shows how.

## Workstation size for a devcontainer

Ringleader doesn't read `hostRequirements` from the file, so the file never changes the size
of the workstation. Size it yourself in `providerConfig`, with room for the container, the
image build and the Docker engine. [Run the devcontainer](https://docs.ringleader.dev/guides/run-devcontainer/#run-the-devcontainer)
sets the size when it declares the workstation.

<div class="callout callout-tip">
  <p class="callout-title">Give the disk the most room</p>
  <div class="callout-body">
    Leave the most room on the disk, because an image build and its layers can take tens of
gigabytes.
  </div>
</div>


## Users in a devcontainer

The workstation's `identity` sets the login user on the virtual machine: SSH login, `sudo`
and home folder. The file's `remoteUser` sets the user in the container, as the format
defines it. You log in as `identity.user` and land in the container as `remoteUser`, and
neither one changes the other.

## Changes to devcontainer.json

A changed `devcontainer.json` doesn't rebuild the container by itself. A rebuild is a full
image build, on a workstation you may be working on, so Ringleader never starts one after a
Git pull. [Rebuild the devcontainer](https://docs.ringleader.dev/guides/run-devcontainer/#rebuild-the-devcontainer) shows how to
start one yourself.

## Supported devcontainer.json settings

Ringleader runs the file with the reference implementation and doesn't interfere with these
settings, which work as that implementation runs them:

- All three build shapes: `image`, `build.dockerfile`, and `dockerComposeFile` with
  `service` and `runServices`.
- Features, with their options and install order.
- The lifecycle commands that run in the container (`onCreateCommand`,
  `updateContentCommand`, `postCreateCommand`, `postStartCommand`) and `waitFor`.
- `remoteUser`, `containerUser` and `updateRemoteUserUID`.
- `workspaceFolder` and `workspaceMount`.
- `containerEnv` and `remoteEnv`.
- `mounts`, `overrideCommand`, `init`, `privileged`, `capAdd`, `securityOpt` and `runArgs`.

## Unsupported devcontainer.json settings

These parts of the format don't work on a workstation, each for the reason given:

| Not supported | Reason |
|---|---|
| Forwarding `forwardPorts` to your computer | Reaching a container port from your computer takes a `ports` or [LocalBinding](https://docs.ringleader.dev/reference/resources/localbinding/) declaration. |
| `customizations` | They are specific to each tool. `customizations.vscode.extensions` may be added later. |
| `initializeCommand` | It is meant to run on your computer before the container starts, and Ringleader runs nothing on your computer for a devcontainer. Don't rely on it. |
| `postAttachCommand` | `rl shell` connects over SSH, which has no attach event to run it on. |
| `shutdownAction` | Ringleader decides when a workstation stops, from `stopped`, `ttl` and deletion, not a file in a repository. |
| `hostRequirements` | Ignored. Size the workstation in `providerConfig`, as [Workstation size for a devcontainer](#workstation-size-for-a-devcontainer) describes. |

<div class="callout callout-warning">
  <p class="callout-title">Images and Features are not verified</p>
  <div class="callout-body">
    Ringleader checks no signature or provenance on the <code>image</code>, the <code>build.dockerfile</code> base or
any Feature.
  </div>
</div>


## Next steps

- [Run a repository's devcontainer](https://docs.ringleader.dev/guides/run-devcontainer/) builds a
  devcontainer, forwards a port, rebuilds it and repairs a failed build, one step at a time.
- [Code sources](https://docs.ringleader.dev/reference/resources/workstationconfig/#code-sources) lists the
  `devcontainer` fields beside the other source fields.
- [docker](https://docs.ringleader.dev/reference/tools/devtools/docker/) and
  [devcontainer-cli](https://docs.ringleader.dev/reference/tools/devtools/devcontainer-cli/) describe the two
  devtools a devcontainer adds.

