Dev Containers を試す
環境
VSCode のコマンドから "Try a Dev Container Sample" をしてみる とりあえず Java を選んでみる
https://github.com/Microsoft/vscode-remote-try-* から選んだ
cpp, go, java, dotnet, node, php, python, rust があった
普通にダウンロードしながらのビルドが始まり、数分で完了した
ビルドログには docker:orbstack と表示され、右下は「開発コンテナー: Java @ orbstack」となっている
src/main/略/App.java には System.out.println("Hello Remote World!"); などと書かれている
実行とデバッグタブから Launch App を実行してみる
Hello Remote World! と表示された。はやい!
.devcontainer ディレクトリには devcontainer.json のみ入っている
docker compose ls で何も出ないので、 compose を使わずやってる様子?
code:log
$ docker compose ls
NAME STATUS CONFIG FILES
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vsc-vscode-remote-try-java-562126e00b6ad54b40a10300c10263ba753fd9071ee6491400470b7e7813ad9b-features latest 101c0720e448 4 minutes ago 1.3GB
vsc-volume-bootstrap latest b9546c672f13 5 minutes ago 800MB
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64b60ef57042 vsc-vscode-remote-try-java-562126e00b6ad54b40a10300c10263ba753fd9071ee6491400470b7e7813ad9b-features "/bin/sh -c 'echo Co…" 4 minutes ago Up 4 minutes keen_goodall
code:devcontainer.json
{
"name": "Java",
"image": "mcr.microsoft.com/devcontainers/java:0-17",
"features": {
"ghcr.io/devcontainers/features/java:1": {
"version": "none",
"installMaven": "true",
"mavenVersion": "3.8.6",
"installGradle": "false"
}
},
"customizations": {
"vscode": {
"settings": {},
"extensions": [
"streetsidesoftware.code-spell-checker"
]
}
}
// 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": "java -version",
// "remoteUser": "root"
}
拡張機能をみると streetsidesoftware.code-spell-checker 以外にもいろいろ入っているな
vscjava.vscode-java-pack が書かれてる
GitHub Pull Requests and Issues と ESLint は?
謎
もう 1 つの環境構築方法っぽい Add Dev Container Configuration Files... もやってみる
Alpine, 3.18, Spring Boot, JDK version はデフォルトの latest, JDK distribution はデフォルトの ms を選んでみる
こうなった:
code:devcontainer.2.json
{
"name": "Alpine",
"image": "mcr.microsoft.com/devcontainers/base:alpine-3.19",
"features": {
"ghcr.io/devcontainers-contrib/features/springboot-sdkman:2": {
"version": "latest",
"jdkVersion": "latest",
"jdkDistro": "ms"
}
}
}
通知から「コンテナーで再度開く」を選択
エラーだ
code:log
0.249 bash: cannot set terminal process group (1): Not a tty
0.249 bash: no job control in this shell
------
Dockerfile.extended:24
--------------------
23 |
24 | >>> RUN --mount=type=bind,from=dev_containers_feature_content_source,source=springboot-sdkman_0,target=/tmp/build-features-src/springboot-sdkman_0 \
25 | >>> cp -ar /tmp/build-features-src/springboot-sdkman_0 /tmp/dev-container-features \
26 | >>> && chmod -R 0755 /tmp/dev-container-features/springboot-sdkman_0 \
27 | >>> && cd /tmp/dev-container-features/springboot-sdkman_0 \
28 | >>> && chmod +x ./devcontainer-features-install.sh \
29 | >>> && ./devcontainer-features-install.sh \
30 | >>> && rm -rf /tmp/dev-container-features/springboot-sdkman_0
31 |
--------------------
ERROR: failed to solve: process "/bin/sh -c cp -ar /tmp/build-features-src/springboot-sdkman_0 /tmp/dev-container-features && chmod -R 0755 /tmp/dev-container-features/springboot-sdkman_0 && cd /tmp/dev-container-features/springboot-sdkman_0 && chmod +x ./devcontainer-features-install.sh && ./devcontainer-features-install.sh && rm -rf /tmp/dev-container-features/springboot-sdkman_0" did not complete successfully: exit code: 22
うーん謎
これ後回しでいいかも
最初に Alpine を選ぶんじゃなくて最初に Java を選んでやるとよさそう