You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2022-11-01-author-a-feature.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: "@joshspicer"
5
5
authorUrl: https://github.com/joshspicer
6
6
---
7
7
8
-
Development container ['Features'](/features) are self-contained, shareable units of installation code and development container configuration. We [define a pattern](/implementors/features-distribution) for authoring and self-publishing Features.
8
+
Development container ["Features"](/features) are self-contained, shareable units of installation code and development container configuration. We [define a pattern](/implementors/features-distribution) for authoring and self-publishing Features.
9
9
10
10
In this document, we'll outline a "quickstart" to help you get up-and-running with creating and sharing your first Feature. You may review an example along with guidance in our [devcontainers/feature-starter](https://github.com/devcontainers/feature-starter) repo as well.
title: "Using Images, Dockerfiles, and Docker Compose"
4
+
author: "@chuxel"
5
+
authorUrl: https://github.com/chuxel
6
+
---
7
+
8
+
When creating a development container, you have a variety of different ways to customize your environment like ["Features"](/features) or [lifecycle scripts](implementors/json_reference/#lifecycle-scripts). However, if you are familiar with containers, you may want to use a [Dockerfile](#dockerfile) or [Docker Compose / Compose](#docker-compose) to customize your environment. This article will walk through how to use these formats with the Dev Container spec.
9
+
10
+
## <ahref="dockerfile"name="dockerfile"class="anchor"> Using a Dockerfile </a>
11
+
12
+
To keep things simple, many [Dev Container Templates](/templates) use container image references.
However, [Dockerfiles](https://docs.docker.com/engine/reference/builder/) are a great way to extend images, add additional native OS packages, or make minor edits to the OS image. You can reuse any Dockerfile, but let's walk through how to create one from scratch.
21
+
22
+
First, add a file named `Dockerfile` next to your `devcontainer.json`. For example:
23
+
24
+
```Dockerfile
25
+
FROM mcr.microsoft.com/devcontainers/base:ubuntu
26
+
# Install the xz-utils package
27
+
RUN apt-get update && apt-get install -y xz-utils
28
+
```
29
+
30
+
Next, remove the `image` property from `devcontainer.json` (if it exists) and add the `build` and `dockerfile` properties instead:
31
+
32
+
```json
33
+
{
34
+
"build": {
35
+
// Path is relataive to the devcontainer.json file.
36
+
"dockerfile": "Dockerfile"
37
+
}
38
+
}
39
+
```
40
+
41
+
That's it! When you start up your Dev Container, the Dockerfile will be automatically built with no additional work. See [Dockerfile scenario reference](implementors/json_reference/#image-specific) for more information on other related devcontainer.json properties.
42
+
43
+
### <ahref="dockerfile-image-iteration"name="dockerfile-image-iteration"class="anchor"> Iterating on an image that includes Dev Container metadata </a>
44
+
45
+
Better yet, you can can use a Dockerfile as a part of authoring an image you can share with others. You can even **add Dev Container settings and metadata right into the image itself**. This avoids having to duplicate config and settings in multiple devcontainer.json files and keeps them in sync with your images!
46
+
47
+
See the reference on **[pre-building](/implementors/reference/#prebuilding)** to learn more!
48
+
49
+
## <ahref="docker-compose"name="docker-compose"class="anchor"> Using a Dockerfile </a>
50
+
51
+
[Docker Compose](https://docs.docker.com/compose/) is a great way to define a multi-container development environment. Rather than adding things like databases or redis to your Dockerfile, you can reference existing images for these services and focus your Dev Container's content on tools and utilities you need for development.
52
+
53
+
### <ahref="docker-compose-image"name="docker-compose-image"class="anchor"> Using an image with Docker Compose </a>
54
+
55
+
As mentioned in the Dockerfile section, to keep things simple, many [Dev Container Templates](/templates) use container image references.
- `service`indicates which service in the `docker-compose.yml` file is the Dev Container.
106
+
- `dockerComposeFile`indicates where to find the `docker-compose.yml` file.
107
+
- `workspaceFolder`indicates where to mount the workspace folder. This corresponds to a sub-folder under the mount point from `../..:/workspaces:cached` in the `docker-compose.yml` file.
108
+
109
+
That's it!
110
+
111
+
### <a href="docker-compose-dockerfile" name="docker-compose-dockerfile" class="anchor"> Using a Dockerfile with Docker Compose </a>
112
+
113
+
You can also combine these scenarios and use Dockerfile with Docker Compose. This time we'll update `docker-compose.yml` to reference the Dockerfile by replacing `image` with a similar `build` section:
114
+
115
+
```yaml
116
+
version: '3.8'
117
+
services:
118
+
devcontainer:
119
+
build:
120
+
context: .
121
+
dockerfile: Dockerfile
122
+
volumes:
123
+
- ../..:/workspaces:cached
124
+
network_mode: service:db
125
+
126
+
db:
127
+
image: postgres:latest
128
+
restart: unless-stopped
129
+
volumes:
130
+
- postgres-data:/var/lib/postgresql/data
131
+
environment:
132
+
POSTGRES_PASSWORD: postgres
133
+
POSTGRES_USER: postgres
134
+
POSTGRES_DB: postgres
135
+
136
+
volumes:
137
+
postgres-data:
138
+
```
139
+
140
+
Finally, as in the Dockerfile example, you can use this same setup to author a Dev Container image you can share with others and add Dev Container settings and metadata right into the image itself.
141
+
142
+
See the reference on **[pre-building](/implementors/reference/#prebuilding)** to learn more!
## <ahref="#devcontainer-cli"name="devcontainer-cli"class="anchor"> Dev Container CLI </a>
44
+
###<ahref="#devcontainer-cli"name="devcontainer-cli"class="anchor"> Dev Container CLI </a>
45
45
46
-
A dev container command line interface (CLI) that implements this specification. It is in development in the [devcontainers/cli](https://github.com/devcontainers/cli) repo.
46
+
The dev container command line interface (CLI) is a reference implementation for the Dev Container spec. It is in development in the [devcontainers/cli](https://github.com/devcontainers/cli) repo. It is intended both for use directly and by tools or services that want to support the spec.
47
47
48
-
The CLI can take a `devcontainer.json` and create and configure a dev container from it. It allows for prebuilding dev container definitions using a CI or DevOps product like GitHub Actions. It can detect and include dev container features and apply them at container runtime, and run [lifecycle commands](implementors/json_reference/#lifecycle-scripts) like `postCreateCommand`, providing more power than a plain `docker build` and `docker run`.
49
48
50
-
### <ahref="#dev-containers-cli"name="dev-containers-cli"class="anchor"> VS Code extension CLI </a>
49
+
The CLI can take a `devcontainer.json` and create and configure a dev container from it. It allows for prebuilding dev container definitions using a CI or DevOps product like GitHub Actions. It can detect and include dev container features and apply them at container runtime, and run [lifecycle scripts](implementors/json_reference/#lifecycle-scripts) like `postCreateCommand`, providing more power than a plain `docker build` and `docker run`.
51
50
52
-
VS Code has a [CLI](https://code.visualstudio.com/docs/remote/devcontainer-cli) which may be installed within the Dev Containers extension or through the command line.
51
+
#### <ahref="#dev-containers-cli"name="dev-containers-cli"class="anchor"> VS Code extension CLI </a>
52
+
53
+
The [VS Code Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) includes a variation of the devcontainer CLI that adds the ability use the command line to open the a Dev Container in VS Code. It is also automatically updated when the extension updates.
54
+
55
+
Press <kbd>cmd/ctrl</kbd>+<kbd>shift</kbd>+<kbd>p</kbd> or <kbd>F1</kbd> and select the **Dev Containers: Install devcontainer CLI** command to install it.
Cachix's [devenv](https://devenv.sh/) supports automatically generating a `.devcontainer.json` file so you can use it with any Dev Container spec supporting tool. See [devenv documentation](https://devenv.sh/integrations/codespaces-devcontainer/) for detais.
59
+
Cachix's **[devenv](https://devenv.sh/)** now supports automatically generating a `.devcontainer.json` file. This gives you a more convenient and consistent way to use [Nix](https://nixos.org/) with any Dev Container spec supporting tool or service!
60
+
61
+
See [devenv documentation](https://devenv.sh/integrations/codespaces-devcontainer/) for detais.
[Jetpack.io's VS Code extension](https://marketplace.visualstudio.com/items?itemName=jetpack-io.devbox)supports a **Generate Dev Container files** command so you can use Jetpack.io from Dev Container spec supporting tools.
65
+
[Jetpack.io](https://jetpack.io) is a [Nix](https://nixos.org/)-based service for deploying applications. [DevBox](https://www.jetpack.io/devbox/) provides a way to use Nix to generate a development environment. [Jetpack.io's VS Code extension](https://marketplace.visualstudio.com/items?itemName=jetpack-io.devbox)allows you to quickly take advantage of DevBox in any Dev Container spec supporting tool or service.
61
66
67
+
Press <kbd>cmd/ctrl</kbd>+<kbd>shift</kbd>+<kbd>p</kbd> or <kbd>F1</kbd> and select the **Generate Dev Container files** command to get started!
62
68
63
-
### <ahref="#dev-containers"name="dev-containers"class="anchor"> Visual Studio Code Dev Containers </a>
69
+
### <ahref="#dev-containers"name="dev-containers"class="anchor"> VS Code Dev Containers extension </a>
64
70
65
-
The [**Visual Studio Code Dev Containers** extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) lets you use a [Docker container](https://docker.com) as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set. There is more information in the Dev Containers [documentation](https://code.visualstudio.com/docs/remote/containers).
71
+
The [Visual Studio Code Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) lets you use a [Docker container](https://docker.com) as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set. There is more information in the Dev Containers [documentation](https://code.visualstudio.com/docs/remote/containers).
66
72
67
-
> **Tip:** If you make a change to your dev container after having built and connected to it, be sure to run **Dev Containers: Rebuild Container** from the Command Palette (`kbstyle(F1)`) to pick up any changes you make.
73
+
> **Tip:** If you make a change to your dev container after having built and connected to it, be sure to run **Dev Containers: Rebuild Container** from the Command Palette (<kbd>cmd/ctrl</kbd>+<kbd>shift</kbd>+<kbd>p</kbd> or <kbd>F1</kbd>) to pick up any changes you make.
68
74
69
75
#### <ahref="#product-specific-properties"name="product-specific-properties"class="anchor"> Product specific properties </a>
70
76
@@ -82,13 +88,13 @@ Some properties may also have certain limitations in the Dev Containers extensio
82
88
|`${localWorkspaceFolderBasename}`| Any | Not yet supported when using Clone Repository in Container Volume. |
A [codespace](https://docs.github.com/en/codespaces/overview) is a development environment that's hosted in the cloud. Codespaces run on a variety of VM-based compute options hosted by GitHub.com, which you can configure from 2 core machines up to 32 core machines. You can connect to your codespaces from the browser or locally using Visual Studio Code.
88
96
89
-
> **Tip:** If you make a change to your dev container after having built and connected to your codespace, be sure to run **Codespaces: Rebuild Container** from the Command Palette (`kbstyle(F1)`) to pick up any changes you make.
90
-
91
-
> **Tip** Codespaces implements an auto `workspaceFolder` mount in **Docker Compose** scenarios.
97
+
> **Tip:** If you make a change to your dev container after having built and connected to your codespace, be sure to run **Codespaces: Rebuild Container** from the Command Palette (<kbd>cmd/ctrl</kbd>+<kbd>shift</kbd>+<kbd>p</kbd> or <kbd>F1</kbd>) to pick up any changes you make.
92
98
93
99
#### <ahref="#codespaces-specific-properties"name="codespaces-specific-properties"class="anchor"> Product specific properties </a>
94
100
GitHub Codespaces works with a growing number of tools and, where applicable, their `devcontainer.json` properties. For example, connecting the Codespaces web editor or VS Code enables the use of [VS Code properties](#visual-studio-code).
0 commit comments