defraggled
defraggled

Reputation: 1218

VScode remote containers - how to view the dockerised service console output?

This is a follow on from this question (none of the current answers seem hit the nail on the head).

VScode's default behaviour for starting a remote vscode session (using VScode Remote-Containers) seems to be:

  1. Run the project's docker-compose file
    • If the user selects show log (a UI popup) during build, open a VScode terminal session called Dev Containers reflecting Docker's build logging, supplemented with VSCode Remote-Containers logging. This output ends after build complete.
    • If the user didn't select show log, and later opens a VScode terminal after build complete, just start a new bash session within the container. No other VScode terminal sessions exist.
  2. Launch a VScode session from inside the now-running container

From the user's perspective, the container is running, but the output that is happening inside the container seems inaccessible (even if the docker-compose command did not use daemon mode).

So, how can the user now view the console output that is happening inside the container?

If I am reading correctly, VScode Remote-Containers documentation seems to suggest overriding the default behaviour, ie:

Is there no way to:

A) Start the services via system terminal (e.g. docker-compose up), and then start a VSCode remote session in this already running container*, or

B) Accessing the service's output without having to override as above (the override seems hacky)

*This would be ideal. The Remote-Containers "Attach to Running Container..." command sounds close to this. But it seems to instantiate itself in a directory I don't recognise, and doesn't seem to be the container.

Upvotes: 3

Views: 2388

Answers (1)

defraggled
defraggled

Reputation: 1218

Option A seems to be achievable by

  1. Starting the service in terminal (docker-compose up)
  2. In vscode, using the remote-containers "remote explorer" UI (not the cmd+P "Attach to container" commands) to select the running container's working directory. Right click > "Open in container". This doesn't actually open a new container, it "Opens the directory, from within the container".

OR ( thanks @cybercoder )

  1. Letting vscode start the services
  2. In a separate terminal: docker logs -f container_name OR docker-compose logs -f

Upvotes: 3

Related Questions