Devcontainer workstations
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.
Devcontainer declaration
A devcontainer belongs to a checkout, so you declare it on the code source that holds the repository. Only one source on a workstation can run a devcontainer. Declaring one does three things:
- The source’s
pathbecomes the workspace folder. Ringleader mounts the checkout into the container there, as the format expects. A source with nopathis refused. - The
dockeranddevcontainer-clidevtools are added for you. Declare one yourself only to choose its version. - Ringleader adds a service named
devcontainer, which runsdevcontainer upwith 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.
Repair with the host login
<user>-host login to repair a workstation whose container failed to build, or to
point an editor at the virtual machine instead of the container.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. To repair a build, follow Repair a failed build.
Devcontainer readiness
A devcontainer workstation reaches Configured, its
condition 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, 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
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
sets the size when it declares the workstation.
Give the disk the most room
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 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, anddockerComposeFilewithserviceandrunServices. - Features, with their options and install order.
- The lifecycle commands that run in the container (
onCreateCommand,updateContentCommand,postCreateCommand,postStartCommand) andwaitFor. remoteUser,containerUserandupdateRemoteUserUID.workspaceFolderandworkspaceMount.containerEnvandremoteEnv.mounts,overrideCommand,init,privileged,capAdd,securityOptandrunArgs.
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 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 describes. |
Images and Features are not verified
image, the build.dockerfile base or
any Feature.Next steps
- Run a repository’s devcontainer builds a devcontainer, forwards a port, rebuilds it and repairs a failed build, one step at a time.
- Code sources lists the
devcontainerfields beside the other source fields. - docker and devcontainer-cli describe the two devtools a devcontainer adds.