devcontainers / devcontainers/cli

Display container logs if container is not running

Đang mở
#620 1 bình luận 2 reaction 0 người được giao Xem trên GitHub
feature-request
Ngôn ngữ chính
TypeScript
Star
3k
Fork
457
Merge trung bình
13 giờ 17 phút
Pull request đã merge (30 ngày)
6

Mô tả

During `devcontainer up`, the container gets started and then the CLI attempts to run commands inside it, expecting the container to be already up and ready to react to `docker exec`.

However, sometimes the container doesn't keep running for whatever reason. Maybe you are trying out with a different image, maybe you are playing with `docker-compose.yaml`, maybe you are overriding `ENTRYPOINT` or `CMD`, or tweaking `overrideCommand`.

Point is: when this happens, the logs are something like:

```
❯ devcontainer up --workspace-folder .
[1 ms] @devcontainers/cli 0.50.2. Node.js v18.17.1. linux 5.15.90.4-microsoft-standard-WSL2 x64.
Shell server terminated (code: 1, signal: null)

Error response from daemon: Container 135d96f33ad94d7fa876dae075cf6cdaf22b2ed46f55122ee4a4bf9b2eb9a7bb is not running

Error: An error occurred setting up the container.
at oAA (/home/felipecrs/.volta/tools/image/packages/@devcontainers/cli/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:462:1066)
at mK (/home/felipecrs/.volta/tools/image/packages/@devcontainers/cli/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:462:1002)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async mAA (/home/felipecrs/.volta/tools/image/packages/@devcontainers/cli/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:479:3660)
at async LC (/home/felipecrs/.volta/tools/image/packages/@devcontainers/cli/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:479:4775)
at async jeA (/home/felipecrs/.volta/tools/image/packages/@devcontainers/cli/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:611:12219)
at async _eA (/home/felipecrs/.volta/tools/image/packages/@devcontainers/cli/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:611:11960)
{"outcome":"error","message":"An error occurred setting up the container.","description":"An error occurred setting up the container.","containerId":"135d96f33ad94d7fa876dae075cf6cdaf22b2ed46f55122ee4a4bf9b2eb9a7bb"}
```

For this example, I did:

```json
// .devcontainer/devcontainer.json
"containerEnv": {
"PATH": "I messed this up"
},
```

And as you can see, there is simply no indicator on what's actually the issue. Running `docker logs 135d96f33ad94d7fa876dae075cf6cdaf22b2ed46f55122ee4a4bf9b2eb9a7bb`:

```
Container started
/usr/local/share/docker-init.sh: 11: cat: not found
-: 5: sleep: not found
Container started
/usr/local/share/docker-init.sh: 11: cat: not found
-: 5: sleep: not found
```

Gives us a much better hint.

So, here's my suggestion:

1. How about the CLI first check if the container is running before attempting to `docker exec` into it?
2. If 1 fails, automatically run `docker logs ` and present the output to the user.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.