简体   繁体   中英

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!

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":

在此处输入图片说明

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

在此处输入图片说明

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.

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 .

开发容器

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM