devcontainers / devcontainers/cli

Display container logs if container is not running

Aperta
#620 1 commento 2 reazioni 0 assegnatari Vedi su GitHub
feature-request
Lingua principale
TypeScript
Stelle
3k
Fork
457
Merge medio
13h 17m
PR unite (30g)
6

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by tracing the `devcontainer up` flow where it attempts `docker exec` after starting the container, then reproduce the failure with the broken PATH example from the issue. Done means a stopped container is detected before the exec attempt and its `docker logs ` output is presented with the setup error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
docker, typescript
Ambito
cli, devops
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.