parent directory.. | ||||
View all files | ||||
This folder contains a set of basic examples that use the devcontainer CLI for different use cases. It includes example scripts to:
Each should run on macOS or Linux. For Windows, you can use these scripts from WSL2.
All examples use the contents of the workspace folder for their configuration, which is where you can make modifications if you'd like. The example scripts are then in different sub-folders.
You can use these examples by opening a terminal and typing one of the following:
When switching between examples, pass true in as an argument to get the container recreated to avoid port conflicts. e.g., ./start.sh true
In the first two examples, you'll be instructed to go to http://localhost:8000 in a browser.
This also adds a desktop to the container that can be accessed from a web browser at http://localhost:6080 and you can connect using the password vscode.
These examples demonstrate the use of the dev container CLI to:
Simplify setup using the "dev container features" concept. For example, SSH support is added just using a feature reference. See workspace/.devcontainer/devcontainer.json for more information.
How the dev container CLI can be used to inject tools without building them into the base image:
Currently the appPort property is used in devcontainer.json instead of forwardPorts due to a gap in the current dev container CLI (see here).
This example illustrates how you can use the dev container CLI to build your application in any CI system. (Note there is also a GitHub Action and Azure DevOps task if you are using those automation systems, but this example will focus on direct use of the CLI.)
You can use the example by opening a terminal and typing the following:
After the build completes, you can find the built application in the workspace/dist folder.
The initial build can take a bit since it is building the dev container image, which is an example of where pre-building an image helps.
This example demonstrates the use of the dev container CLI to:
Simplify setup using the "dev container features" concept. For example, SSH support is added just using a feature reference. See workspace/.devcontainer/devcontainer.json for more information.
Execute an application build script inside a dev container as follows:
All environment variables are automatically available from exec, including those that are are set in the non-root user's .bashrc file. The dev container CLI also automatically adjusts to UID/GID differences for the user inside the container on Linux to ensure the workspace folder is writable.
You can use the example by opening a terminal and typing the following:
The resulting image name defaults to devcontainer-cli-test-image, but you can change it with the first argument, and configure it to push to a registry by setting the second argument to true. The third argument allows you to build for multiple architectures.
Ultimately, this script just calls the devcontainer build command to do all the work. Once built, you can refer to the specified image name directly in a devcontainer.json file using the image property.