每次当我尝试在 devcontainer 中打开我的代码时,我都会收到此错误:
[2020-04-12T17:35:08.489Z] [PID 4968] [22748 ms] Start: Run: docker ps -q -a --filter label=com.docker.compose.project=nodejs-express-jwt_devcontainer --filter label=com.docker.compose.service=api [2020-04-12T17:35:08.591Z] [PID 4968] [22850 ms] Start: Run: docker inspect --type container ad270338d286 [2020-04-12T17:35:10.986Z] [PID 4968] [25245 ms] Start: Inspecting container [2020-04-12T17:35:10.986Z] [PID 4968] [25245 ms] Start: Run: docker inspect --type container ad270338d286ba6db0560a94fd7a826bb563f17299799bfc1b8488becea02091 [2020-04-12T17:35:14.884Z] [PID 4968] [29143 ms] Start: Run: docker exec -i -u node -e VSCODE_REMOTE_CONTAINERS_SESSION=6351885a-14c9-4520-8ac6-db1d1e4218231586712884962 ad270338d286ba6db0560a94fd7a826bb563f17299799bfc1b8488becea02091 /bin/sh [2020-04-12T17:35:14.899Z] [PID 4968] [29158 ms] Start: Run in container: uname -m [2020-04-12T17:35:27.282Z] [PID 4968] [41541 ms] Start: Run in container: cat /etc/passwd [2020-04-12T17:35:27.282Z] [PID 4968] [41541 ms] Stdin closed! [2020-04-12T17:35:27.285Z] [PID 4968] [41544 ms] Shell server terminated (code: 1, signal: null) No such exec instance: 43330c7272221ead535677993be73423b5f6bdb8497429ee7380a81bb43bce59
我的 .devcontainer 中有这个文件
Docker 文件
FROM node:12.16-alpine
#Linux setup
RUN apk update \
&& apk add --update alpine-sdk \
&& apk add --no-cache git \
&& apk add --no-cache npm \
&& npm cache verify
# && sed -i -e "s/bin\/ash/bin\/sh/" /etc/passwd
RUN git config --global user.email "my@email.com" \
&& git config --global user.name "My Name"
docker-composer.yml
version: '3.3'
services:
api:
build: .
restart: always
depends_on:
- db
ports:
- 3000:80
environment:
DB_HOST: db
DB_USER: apiuser
DB_PASSWORD: apipass
DB_NAME: apidb
# volumes:
# - ./src:/var/www/html/wp-content/plugins/meu-plugin
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: apidb
MYSQL_USER: apiuser
MYSQL_PASSWORD: apipass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
adminer:
depends_on:
- db
image: adminer
restart: always
ports:
- 8888:8080
networks:
back:
volumes:
db:
devcontainer.json
{
"name": "Node.js",
// "dockerFile": "Dockerfile",
"service": "api",
"dockerComposeFile": "docker-compose.yml",
// Use 'appPort' to create a container with published ports. If the port isn't working, be sure
// your server accepts connections from all interfaces (0.0.0.0 or '*'), not just localhost.
"appPort": [3000],
// Comment out the next line to run as root instead.
"remoteUser": "node",
// Use 'settings' to set *default* container specific settings.json values on container create.
// You can edit these settings after create using File > Preferences > Settings > Remote.
"settings": {
"terminal.integrated.shell.linux": "/bin/sh"
},
// Specifies a command that should be run after the container has been created.
// "postCreateCommand": "yarn install",
// Add the IDs of extensions you want installed when the container is created in the array below.
"extensions": [
"dbaeumer.vscode-eslint"
]
}
我不知道为什么这不起作用......
最佳答案
我认为问题可能是您的 api 容器在运行 git config 命令后终止。您是否尝试添加
command: sleep infinity
到您的 docker-compose.yml
中的 api 服务?
关于Docker VS 代码移除 devcontainer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61175598/