Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dev containers content #5587

Merged
merged 16 commits into from
Sep 2, 2022
53 changes: 36 additions & 17 deletions docs/remote/containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ This quick start covers how to set up a dev container for an existing project to

The list will be automatically sorted based on the contents of the folder you open.

You may be able to customize your dev container with additional features, which [you can read more about below](#dev-container-features-preview).
You may be able to customize your dev container with additional Features, which [you can read more about below](#dev-container-features-preview).

The dev container definitions displayed come from the [vscode-dev-containers repository](https://aka.ms/vscode-dev-containers). You can browse the `containers` folder of that repository to see the contents of each definition.

Expand Down Expand Up @@ -260,45 +260,58 @@ Selecting the **Remote-Containers: Add Development Container Configuration Files

To learn more about creating `devcontainer.json` files, see [Create a Development Container](/docs/remote/create-dev-container.md).

## Dev container features (preview)
## Dev Container Features (preview)

Dev container features provide a smooth path for customizing your container definitions.
Development container "Features" are self-contained, shareable units of installation code and dev container configuration. The name comes from the idea that referencing one of them allows you to quickly and easily add more tooling, runtime, or library "Features" into your development container for you or your collaborators to use.

When you use **Remote-Containers: Add Development Container Configuration Files**, you're presented a list of scripts to customize the existing dev container configurations, such as installing Git or the Azure CLI:

![Dev container features in Command Palette](images/containers/container-features.png)
![Dev container Features in Command Palette](images/containers/container-features.png)

When you rebuild and reopen in your container, the features you selected will be available in your `devcontainer.json`:
When you rebuild and reopen in your container, the Features you selected will be available in your `devcontainer.json`:

```json
"features": {
"github-cli": "latest"
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "latest"
}
}
```

You'll get IntelliSense when editing the `"features"` property in the `devcontainer.json` directly:

![Intellisense when modifying terraform feature](images/containers/features-intellisense.png)
![Intellisense when modifying terraform Feature](images/containers/features-intellisense.png)

Built-in features are sourced from the [script library](https://github.com/microsoft/vscode-dev-containers/tree/main/script-library/docs) folder in the vscode-dev-containers repo, but the Remote - Containers extension and GitHub Codespaces include an **early preview** for creating your own dev container features. For example, you can reference these as follows:
The **Remote-Containers: Configure Container Features** command allows you to update an existing configuration.

```json
"features": {
"your-github-id-or-org/your-repository/[email protected]": "latest"
}
The Features sourced in VS Code UI come from the [`devcontainers/features` repository](https://github.com/devcontainers/features).

### Creating your own feature

It's also easy to create and publish your own Dev Container Features. Published Features can be stored and shared as [OCI Artifacts](https://github.com/opencontainers/artifacts) from any supporting public or private container registry. You can see the list of current published Features on [containers.dev](https://containers.dev/features.html).

A Feature is a self contained entity in a folder with at least a `devcontainer-feature.json` and `install.sh` entrypoint script:

```
+-- feature
| +-- devcontainer-feature.json
| +-- install.sh
| +-- (other files)
```

The form and format of these custom features is still in flux, but you can try creating your own dev container feature using the [dev-container-features-template](https://github.com/microsoft/dev-container-features-template) sample repository. Let us know what you think!
See the [latest template](https://github.com/devcontainers/feature-template) for instructions on using the dev container CLI to publish your own public or private Features!

The **Remote-Containers: Configure Container Features** command allows you to update an existing configuration.
### Features proposal and distribution

Features are an active proposal in the open dev container specification. You can review the [Features proposal](https://github.com/devcontainers/spec/issues/61), along with [greater information about how Features work](https://containers.dev/implementors/features/) and their [distribution](https://containers.dev/implementors/features-distribution/).

## Pre-building dev container images

We recommend pre-building images with the tools you need rather than creating and building a container image each time you open your project in a dev container. Using pre-built images will result in a faster container startup, simpler configuration, and allows you to pin to a specific version of tools to improve supply-chain security and avoid potential breaks. You can automate pre-building your image by scheduling the build using a DevOps or continuous integration (CI) service like GitHub Actions.

We recommend using the [devcontainer CLI](/docs/remote/devcontainer-cli.md) to pre-build your images since it is kept in sync with the Remote - Container extension's latest capabilities - including [dev container features](#dev-container-features-preview). Once you've built your image, you can push it to a container registry (like the [Azure Container Registry](https://docs.microsoft.com/azure/container-registry/container-registry-get-started-docker-cli?tabs=azure-cli), [GitHub Container Registry](https://docs.github.com/packages/working-with-a-github-packages-registry/working-with-the-container-registry#pushing-container-images), or [Docker Hub](https://docs.docker.com/engine/reference/commandline/push)) and reference it directly.
We recommend using the [devcontainer CLI](/docs/remote/devcontainer-cli.md) to pre-build your images since it is kept in sync with the Remote - Container extension's latest capabilities - including [dev container Features](#dev-container-features-preview). Once you've built your image, you can push it to a container registry (like the [Azure Container Registry](https://docs.microsoft.com/azure/container-registry/container-registry-get-started-docker-cli?tabs=azure-cli), [GitHub Container Registry](https://docs.github.com/packages/working-with-a-github-packages-registry/working-with-the-container-registry#pushing-container-images), or [Docker Hub](https://docs.docker.com/engine/reference/commandline/push)) and reference it directly.

See the [devcontainer CLI article on pre-building images](/docs/remote/devcontainer-cli.md#building-a-dev-container-image) for more information.
See the [devcontainer CLI article on pre-building images](/docs/remote/devcontainer-cli.md#pre-building) for more information.

## Inspecting volumes

Expand Down Expand Up @@ -695,6 +708,12 @@ The following articles may help answer your question:
* [Docker Desktop for Mac troubleshooting guide](https://docs.docker.com/docker-for-mac/troubleshoot) and [FAQ](https://docs.docker.com/docker-for-mac/faqs/)
* [Docker Support Resources](https://success.docker.com/article/best-support-resources)

### Can I use dev containers outside of VS Code?

As containerizing production workloads becomes commonplace, dev containers have become broadly useful for scenarios beyond VS Code. We're creating the **Development Containers Specification** to empower anyone in any tool to configure a consistent dev environment. It seeks to find ways to enrich existing formats with common development specific settings, tools, and configuration while still providing a simplified, un-orchestrated single container option – so that they can be used as coding environments or for continuous integration and testing.

You can learn more and review the spec on [containers.dev](https://containers.dev), and you can review active proposals and contribute to the spec in the [devcontainers/spec](https://github.com/devcontainers/spec) repository on GitHub.

## Questions or feedback

* See [Tips and Tricks](/docs/remote/troubleshooting.md#container-tips) or the [FAQ](/docs/remote/faq.md).
Expand All @@ -710,4 +729,4 @@ The following articles may help answer your question:
* [Attach to a Running Container](/docs/remote/attach-container.md) - Attach to an already running Docker container.
* [Create a Development Container](/docs/remote/create-dev-container.md) - Create a custom container for your work environment.
* [Advanced Containers](/remote/advancedcontainers/overview.md) - Find solutions to advanced container scenarios.
* [devcontainer.json reference](/docs/remote/devcontainerjson-reference.md) - Review the `devcontainer.json` schema.
* [devcontainer.json reference](https://containers.dev/implementors/json_reference/) - Review the `devcontainer.json` schema.
2 changes: 1 addition & 1 deletion docs/remote/create-dev-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,4 @@ The path used for looking up the configuration is derived from the output of `gi

* [Attach to a Running Container](/docs/remote/attach-container.md) - Attach to an already running Docker container.
* [Advanced Containers](/remote/advancedcontainers/overview.md) - Find solutions to advanced container scenarios.
* [devcontainer.json reference](/docs/remote/devcontainerjson-reference.md) - Review the `devcontainer.json` schema.
* [devcontainer.json reference](https://containers.dev/implementors/json_reference/) - Review the `devcontainer.json` schema.
93 changes: 92 additions & 1 deletion docs/remote/devcontainer-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,104 @@ These steps above are also provided in the CLI repo's [README](https://github.co

If you'd like to use the dev container CLI in your CI/CD builds or test automation, you can find examples of GitHub Actions and Azure DevOps Tasks in the [devcontainers/ci](https://github.com/devcontainers/ci) repository.

## Pre-building

The `devcontainer build` command allows you to build quickly build dev container image following the same steps the Remote - Containers extension or GitHub Codespaces will. This is particularly useful when you want to pre-build a dev container image using a CI or DevOps product like GitHub Actions.

`build` accepts a path to the folder containing a `.devcontainer` folder or `.devcontainer.json` file. For example, `devcontainer build --workspace-folder <my_repo>` will build the container image for `my_repo`.

### Example of building and publishing an image

For example, you may want to pre-build a number of images that you then reuse across multiple projects or repositories. To do so, follow these steps:

1. [Create](/docs/editor/versioncontrol.md#initialize-a-repository) a source code repository.

1. Create dev container configuration for each image you want to pre-build, customizing as you wish (including [dev container Features](#dev-container-features-preview)). For example, consider this devcontainer.json file:

```json
{
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:1": {
"version": "latest"
}
}
}
```

1. Use the `devcontainer build` command to build the image and [push](https://docs.docker.com/engine/reference/commandline/push/) it to your image registry. See documentation for your image registry (like the [Azure Container Registry](https://docs.microsoft.com/azure/container-registry/container-registry-get-started-docker-cli?tabs=azure-cli), [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#pushing-container-images), or [Docker Hub](https://docs.docker.com/engine/reference/commandline/push)) for information on image naming and additional steps like authentication.

```bash
devcontainer build --workspace-folder <my_repo> --push true --image-name <my_image_name>:<optional_image_version>
```

1. You have a couple of options for using your pre-built image:

1. You'd like to use your image in a variety of projects, separate from the repo where you build the image:
* Reference the published image in your other projects' dev containers, and that's it!

1. You'd like a pre-built version of the image in the same repository where you build it:

1. As one option, you may craft a secondary, simplified devcontainer.json file that either uses the `image` property or references it in a Docker Compose file. Include any dev container Features you added in your pre-build configuration. For example:

```json
{
"image": "ghcr.io/your-org/your-image-name",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:1": {
"version": "latest"
}
}
}
```

2. As an alternative, you may use the `cacheFrom` property in your existing devcontainer.json. Like the option above, be sure to include any dev container Features. For example:

```json
{
"build": {
"dockerfile": "Dockerfile",
"cacheFrom": "ghcr.io/your-org/your-image-name"
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker": {}
}
}
```

### [Optional] Avoiding problems with images built using Docker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this too much detail maybe? (Also: Would we want to avoid "vscode" and use "devcontainer" instead?)

Copy link
Member Author

@bamurtaugh bamurtaugh Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, upon a re-read, it does feel a bit specific and VS Code-centric (and while these are VS Code docs, this is the section on the open agnostic CLI). We had added it based on previous user request, but I think that may have been a singular or small number of users, so I don't anticipate this would be a big point of confusion. Removed, cc @Chuxel if you have other thoughts.

Copy link
Member

@Chuxel Chuxel Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit of doc was actually contributed by a user who apparently hit this, so not sure we want to remove it, but it's more of a "tip" than a requirement - it could be moved to an "Advanced" topic (though maybe linked from here?) Agree that using devcontainer-cli as the ARG name is better than vscode tho.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be loosely enough related to https://code.visualstudio.com/remote/advancedcontainers/reduce-docker-warnings, that I could add the info there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a change to add this info in https://code.visualstudio.com/remote/advancedcontainers/reduce-docker-warnings and to point to it from devcontainer-cli.md. I also updated the ARG name to devcontainercli.


Given Dockerfiles and Docker Compose files can be used without VS Code or the `devcontainer` CLI, you may want to let users know that they should not try to build the image directly if it will not work as expected. To solve this problem, you can add a build argument that needs to be specified for things to work.

For example, you could add the following to your Dockerfile:

```bash
ARG vscode
RUN if [[ -z "$vscode" ]] ; then printf "\nERROR: This Dockerfile needs to be built with VS Code !" && exit 1; else printf "VS Code is detected: $vscode"; fi
```

And the following in your `devcontainer.json`:
```json
"build": {
"dockerfile": "Dockerfile",
"args": {
// set vscode arg for Dockerfile
"vscode": "true"
},
}
```

In the Docker Compose case, you can add this argument to a separate [override file to extend your configuration](https://github.com/microsoft/vscode-docs/blob/a55ae5b286196b495e2b3ea9f0b3e211beb7c925/docs/remote/create-dev-container.md#extend-your-docker-compose-file-for-development) that is located in a different place in your source tree than the primary Docker Compose file.

## Feedback

The dev container CLI and specification are under active development and we welcome your feedback, which you can provide in [this issue](https://github.com/devcontainers/cli/issues/7), or through new issues and pull requests in the [devcontainers/cli](https://github.com/devcontainers/cli) repository.

## Next steps

* [Dev container specification repository](https://github.com/devcontainers/spec) - Read and contribute to the open specification.
* [devcontainer.json reference](/docs/remote/devcontainerjson-reference.md) - Review the `devcontainer.json` schema.
* [devcontainer.json reference](https://containers.dev/implementors/json_reference/) - Review the `devcontainer.json` schema.
* [Create a Development Container](/docs/remote/create-dev-container.md) - Create a custom container for your work environment.
* [Advanced Containers](/remote/advancedcontainers/overview.md) - Find solutions to advanced container scenarios.
Loading