我最近从 Visual Studio Code 迁移到 WebStorm,当我尝试在 WebStorm 上运行 devcontainer 时遇到一些问题。
我打开
devcontainer.json
文件,单击文件内的小立方体并选择第二个选项,即“创建开发容器并挂载源...”,然后选择 WebStorm。
这些是我单击 WebStorm 选项后得到的日志:
WARN[0000] /Users/gouvea/www/vtal/vtal-api/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
WARN[0000] /Users/gouvea/www/vtal/vtal-api/.devcontainer/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
[+] Building 0.2s (7/7) FINISHED docker:default
=> [app internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 163B 0.0s
=> [app internal] load metadata for docker.io/library/node:20.5.1-slim 0.0s
=> [app internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [app 1/2] FROM docker.io/library/node:20.5.1-slim 0.0s
=> CACHED [app 2/2] WORKDIR /home/node/app 0.0s
=> [app] exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:ab9f0263bedceecf977b16a0200119f2114dd2c537eaed453025d2b4d076fe57 0.0s
=> => naming to docker.io/library/vtal-api-app 0.0s
=> [app] resolving provenance for metadata file 0.0s
Setting up container features:
Downloading common-utils feature manifest…
Creating directory /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/NOTES.md
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/README.md
Creating directory /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/bin
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/devcontainer-feature.json
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/install.sh
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/main.sh
Creating directory /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/scripts
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/bin/code
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/bin/devcontainer-info
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/bin/systemctl
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/scripts/bash_theme_snippet.sh
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/scripts/devcontainers.zsh-theme
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers/features/common-utils/scripts/rc_snippet.sh
Downloading zsh-plugins feature manifest…
Creating directory /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers-contrib/features/zsh-plugins
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers-contrib/features/zsh-plugins/README.md
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers-contrib/features/zsh-plugins/devcontainer-feature.json
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/devcontainers-contrib/features/zsh-plugins/install.sh
Downloading shell-history feature manifest…
Creating directory /Users/gouvea/.cache/JetBrains/DevContainers/stuartleeks/dev-container-features/shell-history
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/stuartleeks/dev-container-features/shell-history/NOTES.md
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/stuartleeks/dev-container-features/shell-history/README.md
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/stuartleeks/dev-container-features/shell-history/devcontainer-feature.json
Writing file /Users/gouvea/.cache/JetBrains/DevContainers/stuartleeks/dev-container-features/shell-history/install.sh
Creating jb-devcontainer-features-7d8c863c532440ab478baabf115af092…
[+] Building 0.2s (5/5) FINISHED docker:default
=> [internal] load build definition from Dockerfile.features 0.0s
=> => transferring dockerfile: 132B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 50.22kB 0.0s
=> [1/1] COPY . /tmp/jb-devcontainer-features 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:a43cff8ae2c2fedf56a3d03b780d517224e4d8c18325bac0d5d0489732a9778f 0.0s
=> => naming to docker.io/library/jb-devcontainer-features-7d8c863c532440ab478baabf115af092 0.0s
WARN[0000] /Users/gouvea/www/vtal/vtal-api/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
WARN[0000] /Users/gouvea/www/vtal/vtal-api/.devcontainer/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
[+] Running 1/1
! app Warning pull access denied for jb-devcontainer-b2661c53ef1cb9890fb2f98e742a488c, repositor... 2.9s
[+] Building 0.1s (1/1) FINISHED docker:default
=> [app internal] load build definition from .features.temp.dockerfile 0.0s
=> => transferring dockerfile: 2B 0.0s
failed to solve: failed to read dockerfile: open .features.temp.dockerfile: no such file or directory
WARN[0000] /Users/gouvea/www/vtal/vtal-api/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
WARN[0000] /Users/gouvea/www/vtal/vtal-api/.devcontainer/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
[+] Running 1/1
✔ Container vtal-postgres Started 0.2s
`docker-compose` process finished with exit code 17
我真的不明白为什么这总是失败。我尝试更改 Dockerfile 中的一些内容,但总是得到相同的结果...
这是我的
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/docker-existing-docker-compose
{
"name": "vtal api",
"dockerComposeFile": [
"../docker-compose.yaml",
"docker-compose.yml"
],
"service": "app",
"workspaceFolder": "/home/node/app",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
"plugins": "git git-flow F-Sy-H zsh-autosuggestions zsh-completions",
"omzPlugins": "https://github.com/z-shell/F-Sy-H https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-completions"
},
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {}
},
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint"
]
}
}
}
这是我在
docker-compose.yml
文件夹中的 devcontainer
(与 devcontainer.json
文件处于同一级别):
version: '3'
services:
app:
volumes:
- .:/home/node/app:cached
在根文件夹中,我有这个
docker-compose.yaml
:
version: '3'
services:
app:
build: .
container_name: my-api
command: ./.docker/start.sh
ports:
- 8000:8000
volumes:
- .:/home/node/app
postgres:
container_name: my-postgres
image: bitnami/postgresql
ports:
- 5432:5432
environment:
POSTGRES_USER: docker
POSTGRES_PASSWORD: mysupersecret
POSTGRES_DB: mydb
PGDATA: /data/postgres
volumes:
- ./data/pg:/data/postgres
最后但不重要的是,
Dockerfile
:
FROM node:20.5.1-slim
USER node
WORKDIR /home/node/app
CMD ["tail", "-f", "/dev/null"]
尝试将
docker-compose.yaml
文件放在 devcontainer.json
附近。
似乎是 Jetbrains IDE 的问题。