3

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:

  • supress your docker-compose command that would otherwise have started the service, and instead apply some dummy command to persist the container upon creation, then
  • manually start the service (using debug mode, or via VScode terminal) from inside the remote session. This reveals the output, but within an accessible VSCode terminal session.

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.

1
  • 2
    You can follow a container logs with this command: docker logs -f <container_name_or_id> Commented Jan 10, 2021 at 7:17

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Instead of docker logs -f container_name the "remote explorer" UI can be used - just right-click the container and select 'Show Container Log'
This is not a great option, as one of the advantages of docker compose is having all the logs in one place. But it seems to be the only one available now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.