Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view docker logs from vscode remote container?

I'm currently using vscode's remote containers extension with a .devcontainer.json file that points to my docker-compose.yml file.

Everything works fine and my docker-compose start command gets run (which launches a web server), but I haven't found a way to quickly see the logs from the web server. Has anyone found a way to view the docker log output automatically once vscode connects to the remote container?

I know as an alternative I could remove my container's start command and, after vscode connects, manually open a terminal and start the web server, but I'm hoping there's an easier way.

Thanks in advance!

like image 359
Ray J Avatar asked Jul 19 '19 18:07

Ray J


People also ask

How can I see the logs of a docker container?

First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.

How do I connect to remote Docker container VS code?

To attach to a Docker container, either select Remote-Containers: Attach to Running Container... from the Command Palette (F1) or use the Remote Explorer in the Activity Bar and from the Containers view, select the Attach to Container inline action on the container you want to connect to.

How does Vscode remote containers work?

The Visual Studio Code Remote - Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set.


2 Answers

I'm not using remote containers, just local once, so not sure if this applies but for locally running containers, you can go to the "Docker" tab (you need to install the official Microsoft Docker VS Code Plugin) where you can see your running containers. Just right-click on the container you want to see the logs for and select "View Logs":

enter image description here

You'll see a new "Task" appear in the Terminal pane that will show all your docker logs:

enter image description here

like image 84
mvilrokx Avatar answered Oct 05 '22 04:10

mvilrokx


This question is really old and I'm not sure it this option was available at this time but just open the Command Palette (F1) and select/find "Remote-Containers: Show Log".

You see now the log of your container in the terminal.

like image 27
hanscoder Avatar answered Oct 05 '22 05:10

hanscoder