Ray J
Ray J

Reputation: 845

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!

Upvotes: 32

Views: 16587

Answers (7)

Ronald Petty
Ronald Petty

Reputation: 165

For myself, on Mac, both STDOUT and STDERR are showing in "DEBUG CONSOLE".

As others noted, the container state is all I see in the terminal or via "docker logs". Not sure why its done this way.

enter image description here

Upvotes: 0

Luciano
Luciano

Reputation: 486

In the Remote Explorer tab you can see all your docker containers. Under "Dev Containers" is the container for the service specified in devcontainer.json; the rest are in "Other Containers." Simply right click on the container you're interested in and click "Show Container Log." You'll see the full output of the command for that service, just like in an interactive terminal - not a docker build log!

Screenshot

Note I am using a local development container and did not test with remote containers but I'm guessing it's the same.

Upvotes: 0

Vlady Veselinov
Vlady Veselinov

Reputation: 5431

You can open the command palette and search for: Remote Explorer: Focus on containers view. You should see a sidebar of containers, if you right click your container you can view logs.

Upvotes: 7

mvilrokx
mvilrokx

Reputation: 1658

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

Upvotes: 16

hanscoder
hanscoder

Reputation: 79

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.

Upvotes: 5

Felix Fong
Felix Fong

Reputation: 985

Maybe this is too late? But for others, this is how I do it.

First, instead of logging stuff to the stdout, I redirect all of the outputs into one single file and then using the tail command to steam the output to the terminal instead.

For example, I am going Go here:

logFile, err := os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE, 0755)
if err != nil {
  log.Fatal("Fail to open the log file")
}
logrus.SetOutput(logFile)

Once that's done, I open up my terminal and run my the following command:

$ tail -f {logFileName}


That's one way to do it I guess, but I sure hope VSCode can come up with a better solution.

Upvotes: 0

Kin
Kin

Reputation: 1465

I use VS Code's builtin terminal to see the live logs of the docker container that is connected with VS Code.

When VS Code is connected to the docker container, you can open the builtin terminal using the View > Terminal menu option. You should see an existing terminal labeled Dev Containers.

Dev Containers

Upvotes: 1

Related Questions