-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Multi-Architecture for Containers Documentation #5174
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2700d9b
multiarchitecture build update
KanishkT123 e166a3e
Typo
KanishkT123 187a13e
Typo
KanishkT123 3d823c3
Added doc changes per reviewer comments
KanishkT123 3458079
Merge branch 'microsoft:main' into update/multiarch
KanishkT123 d641812
Update devcontainer-cli.md
KanishkT123 4e2ab73
Update devcontainer-cli.md
KanishkT123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,18 @@ The `devcontainer build` command allows you to quickly build dev container image | |
|
||
As with the `open` command, `build` accepts a path to the folder containing a `.devcontainer` folder or `.devcontainer.json` file. If omitted, the current working folder is used. For example, `devcontainer build` will build the dev container image for the current folder and `devcontainer build /source/my-folder` will build the container image for the `/source/my-folder` folder. | ||
|
||
You can use `devcontainer build -h` to see the supported `build` options. | ||
```bash | ||
Options: | ||
-h, --help Show help [boolean] | ||
--disable-telemetry Disable telemetry [boolean] [default: false] | ||
--verbose Run build with increased log level [boolean] [default: false] | ||
--no-cache disable image cache for the dev container build [boolean] [default: false] | ||
--image-name specify the image name [string] | ||
--platform build platforms and push to container registry [string] | ||
--no-push do not push to container registry [boolean] | ||
``` | ||
|
||
### Example of building and publishing an image | ||
|
||
For example, you may want to pre-build several images that you then reuse across multiple projects or repositories. To do so, follow these steps: | ||
|
@@ -126,7 +138,75 @@ For example, you may want to pre-build several images that you then reuse across | |
|
||
That's it! | ||
|
||
### Adding automation | ||
## Building Multi-Architecture builds | ||
|
||
#### Pre-requisites | ||
1. [Node.js 14+](https://nodejs.org). | ||
2. [The `docker` CLI](/docs/remote/containers#installation). | ||
3. [Docker `Buildx`](https://docs.docker.com/buildx/working-with-buildx/) | ||
4. [Docker logged in to a Dockerhub registry](https://docs.docker.com/engine/reference/commandline/login/) | ||
|
||
Ensure that the command `docker buildx -h` returns a valid help message. | ||
|
||
Docker needs to be logged in to a container registry because the multi-architecture build defaults to pushing the multi-arch image manifesto to a container registry. If not, the `--no-push` option needs to be used. | ||
|
||
#### Process Example | ||
|
||
1. Create a basic Dockerfile as below: | ||
|
||
```Dockerfile | ||
ARG VARIANT=3.13 | ||
FROM mcr.microsoft.com/vscode/devcontainers/base:0-alpine-${VARIANT} | ||
CMD echo "Running on $(uname -m)" | ||
``` | ||
|
||
2. Create a basic `devcontainer.json` as below: | ||
|
||
```json | ||
{ | ||
"name": "Alpine", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"args": { "VARIANT": "3.15" }, | ||
"settings": {}, | ||
"extensions": [], | ||
"remoteUser": "vscode" | ||
} | ||
} | ||
``` | ||
|
||
3. Place both files in a `.devcontainer` directory. | ||
|
||
4. Run the below command: | ||
|
||
```bash | ||
devcontainer build \ | ||
--platform linux/amd64,linux/arm64 \ | ||
--image-name hubusername/multiarch-test:v1 \ | ||
path-to-devcontainer-json | ||
``` | ||
|
||
#### Breaking down the command | ||
|
||
1. `devcontainer build`: As before, this invokes the devcontainer CLI build command. | ||
2. `--platform linux/amd64,linux/arm64`: This creates Docker images for the `linux/amd64` and `linux/arm64` architectures. Find other supported platforms [here](https://docs.docker.com/engine/install/) (all Docker supported platforms are supported) and [here](https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#platform) on the Docker Buildx documentation page. | ||
4. `--image-name hubusername/multiarch-test:v1`: **This is mandatory when using `--platform` and optional otherwise.** This will tag the image and needs to follow container registry naming conventions to upload. | ||
|
||
#### No Push | ||
|
||
By default, the Devcontainer CLI **will push** to the container registry when multi-platform builds are specified. To run a multi-paltform build for local development purposes, append `--no-push` to the command as shown below: | ||
|
||
```bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. overall LGTM -- I did notice something appears to be affecting the '3-backtick-formatting' in this "No Push" section, since I see the 3-backtick chars displayed, even with the text fully "MD rendered" ? |
||
devcontainer build \ | ||
--platform linux/amd64,linux/arm64 \ | ||
--no-push \ | ||
--image-name hubusername/multiarch-test:v1 \ | ||
change-me-to-repository-folder-with-dot-devcontainer | ||
``` | ||
|
||
`--no-push` makes the images inaccessible for local development, but allows for the build process to be tested locally. This is because Docker does not currently support building and running multi-architecture images locally. | ||
|
||
## Adding automation | ||
|
||
Steps to automate pre-building your image will vary by CI/DevOps system, but here's an example GitHub Actions workflow that will automate the process for a subfolder called `change-me` and push it to GitHub Container Registry once a month and whenever the dev container folder is modified in the `main` branch: | ||
|
||
|
@@ -169,7 +249,7 @@ jobs: | |
docker push "${IMAGE_REPOSITORY}" | ||
``` | ||
|
||
### devcontainer CLI build options | ||
## devcontainer CLI build options | ||
|
||
The following options can be used with the `build` command: | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.