はじめに
開発環境を開発者に提供する時、"×××をインストールして"とか"×××を設定して"とかを各自に同じことをしてもらったり、
他のプロジェクトで開発しているツールやミドルウェアが入っているのに、いちいちそれらを切り替えたり追加で何かをインストールしたくない。
そんな不満へのソリューションの1つに、Visual Studio Codeで利用できるDev Containersがあります。
社内向けアプリの開発で導入したのですが、ベース イメージのバージョン指定(Tag)がよくわからなかったため、まとめてみました。
Dev Containersとは
Visual Studioの拡張機能とDockerを利用して、開発に特化した環境を構築・再利用できる仕組みです。
拡張機能のDev Containersは2023/4/13現在、プレビュー扱いとなっています。
Visual Studio Code 拡張機能での操作
DockerやDev Containers拡張機能はインストールされた状態とします。
何もないディレクトリをカレントにしてVS Code左下にある><のような記号の部分をクリックすると、ドロップダウンが現れます。

-
Select a container configuration template
Node.js & JavaScript をクリックします。

-
Node.js version (use-bullseye variants on local arm64/Apple Silicon):
18 (default) をクリックします。

-
Select additional features to install
インストールする追加機能(Azure CLIやTerraform等)を選択し、OK をクリックします。
必要がなければ選択する必要はありません。

-
Reading Dev Container Configuration ~ Starting Dev Container
しばらく待つと、左下の表示が>< Dev Container: Node.jsに変わり、.devcontainer/devcontainer.jsonというファイルが作成されます。
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node
{
"name": "Node.js",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/javascript-node:0-18"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
イメージは、javascript-node:0-18になっています。
バージョン タグについて
Dev Containers拡張機能で選択したものと作成されるdevcontainer.jsonファイルの image のバージョン関係は次のようになります。
| Dev Containers | devcontainer.json |
|---|---|
| 18 | 0-18 |
| 16 | 0-16 |
| 14 | 0-14 |
| 18-bullseye | 0-18-bullseye |
| 16-bullseye | 0-16-bullseye |
| 14-bullseye | 0-14-bullseye |
| 18-buster | 0-18-buster |
| 16-buster | 0-16-buster |
| 14-buster | 0-14-buster |
チームでは、Node.jsは18で開発することは決まっている。
Debianは11 bullseyeを使う。
0って何?
という事で、この開発用イメージのドキュメントを見てみました。
You can also directly reference pre-built versions of
.devcontainer/base.Dockerfileby using theimageproperty in.devcontainer/devcontainer.jsonor updating theFROMstatement in your ownDockerfilewith one of the following:
mcr.microsoft.com/vscode/devcontainers/javascript-node(latest)mcr.microsoft.com/vscode/devcontainers/javascript-node:18(or18-bullseye,18-busterto pin to an OS version)mcr.microsoft.com/vscode/devcontainers/javascript-node:16(or16-bullseye,16-busterto pin to an OS version)mcr.microsoft.com/vscode/devcontainers/javascript-node:14(or14-bullseye,14-busterto pin to an OS version)You can decide how often you want updates by referencing a semantic version of each image. For example:
mcr.microsoft.com/vscode/devcontainers/typescript-node:0-16(or0-16-bullseye,0-16-buster)mcr.microsoft.com/vscode/devcontainers/typescript-node:0.204-16(or0.204-16-bullseye,0.204-16-buster)mcr.microsoft.com/vscode/devcontainers/typescript-node:0.204.0-16(or0.204.0-16-bullseye,0.204.0-16-buster)However, we only do security patching on the latest non-breaking, in support versions of images (e.g.
0-16). You may want to runapt-get update && apt-get upgradein your Dockerfile if you lock to a more specific version to at least pick up OS security updates.See history for information on the contents of each version and here for a complete list of available tags.
日本語訳(by Google):
.devcontainer/devcontainer.jsonのimageプロパティを使用するか、独自のDockerfileのFROMステートメントを次のいずれかで更新することにより、.devcontainer/base.Dockerfileのビルド済みバージョンを直接参照することもできます。
mcr.microsoft.com/vscode/devcontainers/javascript-node(最新)mcr.microsoft.com/vscode/devcontainers/javascript-node:18(または OS バージョンに固定するための18-bullseye、18-buster)mcr.microsoft.com/vscode/devcontainers/javascript-node:16(または OS バージョンに固定するための16-bullseye、16-buster)mcr.microsoft.com/vscode/devcontainers/javascript-node:14(または OS バージョンに固定するための14-bullseye、14-buster)各イメージのセマンティック バージョンを参照することで、更新頻度を決定できます。例えば、
mcr.microsoft.com/vscode/devcontainers/typescript-node:0-16(または0-16-bullseye,0-16-buster)mcr.microsoft.com/vscode/devcontainers/typescript-node:0.204-16(または0.204-16-bullseye,0.204-16-buster)mcr.microsoft.com/vscode/devcontainers/typescript-node:0.204.0-16(または0.204.0-16-bullseye,0.204.0-16-buster)
ただし、セキュリティ パッチは、サポート バージョンのイメージ (例:0-16) で、最新の非破壊的なものにのみ適用されます。 少なくとも OS セキュリティ アップデートを取得するために、より具体的なバージョンにロックする場合は、Dockerfile で「apt-get update && apt-get upgrade」を実行することをお勧めします。
0-18-bullseyeと18-bullseyeの違いがわからない...
タグを見てみると
{
"name": "vscode/devcontainers/javascript-node",
"tags": [
// ...
"0-14",
"0-14-bullseye",
"0-14-buster",
"0-14-stretch",
"0-16",
"0-16-bullseye",
"0-16-buster",
"0-18",
"0-18-bullseye",
"0-18-buster",
"0-bullseye",
"0-buster",
// ...
"0.204.19-14",
"0.204.19-14-bullseye",
"0.204.19-14-buster",
"0.204.19-16",
"0.204.19-16-bullseye",
"0.204.19-16-buster",
"0.204.19-18",
"0.204.19-18-bullseye",
"0.204.19-18-buster",
"0.204.19-bullseye",
// ...
"0.204.20-14",
"0.204.20-14-bullseye",
"0.204.20-14-buster",
"0.204.20-16",
"0.204.20-16-bullseye",
"0.204.20-16-buster",
"0.204.20-18",
"0.204.20-18-bullseye",
"0.204.20-18-buster",
"0.204.20-bullseye",
"0.204.20-buster",
// ...
"14",
"14-bullseye",
"14-buster",
"14-stretch",
"16",
"16-bullseye",
"16-buster",
"18",
"18-bullseye",
"18-buster",
"bullseye",
"buster",
// ...
"latest"
]
}
そしてここにヒントが
Tags:
mcr.microsoft.com/devcontainers/javascript-node:0.204.20-18-bullseye mcr.microsoft.com/devcontainers/javascript-node:0.204.20-18 mcr.microsoft.com/devcontainers/javascript-node:0.204.20-bullseyeTo keep up to date, we recommend using partial version numbers. Use the major version number to get all non-breaking changes (e.g.
0-) or major and minor to only get fixes (e.g.0.200-).
つまり、
-
javascript-node:0.204.20-18-bullseyeのタグの読み方は、-
0.204.20: 開発用イメージ(Node.js & JavaScript)のバージョン -
18: Node.jsのバージョン -
bullseye: Debianのバージョン
-
そして、いずれかを省略する場合
-
0.204.20-18- 開発用イメージ : 0.204.20
- Node.js : 18
- Debian : latest
-
0.204.20-bullseye- 開発用イメージ : 0.204.20
- Node.js : latest
- Debian : bullseye
-
0.204-18-bullseye- 開発用イメージ : 0.204.latest
- Node.js : 18
- Debian : bullseye
-
0-18-bullseye- 開発用イメージ : 0.latest.latest
- Node.js : 18
- Debian : bullseye
-
18-bullseye- 開発用イメージ : latest
- Node.js : 18
- Debian : bullseye
ちなみに
-
0.204-18-bullseye- 開発用イメージ : 0.204.latest
- Node.js : 18
- Debian : bullseye
-
0.204.18-bullseye- 開発用イメージ : 0.204.18
- Node.js : latest
- Debian : bullseye
↑のように、ハイフンとピリオドで区切り位置が変わります。
そして、
-
0-bullseye- 開発用イメージ : 0.latest.latest
- Node.js : latest
- Debian : bullseye
18-bullseyeが Node.js : 18 なので0-bullseyeなら Node.js : 0 になるのでは?
とか開発用イメージのバージョンが18まで上がっていたらどうするのだろうとか
へそ曲がりな事を思いましたが、当然違います。
Gitリポジトリ上でのTagは開発用イメージのバージョンではなくDev Containers全てのバージョンなので、混乱しました。
Rubyとかも同じような形式でした。
