devcontainers / devcontainers/cli

Display container logs if container is not running

Open
#620 1 comment 2 reactions 0 assignees View on GitHub
feature-request
Dominant language
TypeScript
Stars
3k
Forks
457
Avg merge
13h 17m
Merged PRs (30d)
6

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.