How to view Docker container application logs

How to view Docker container application logs

docker attach command

docker attach [options] 容器will connect to the running container and then print out the container's standard input, output, and error stream information locally. There are three possible values ​​for options in the command: --detach-keys , --no-stdin , --sig-proxy .

This command just enters the container terminal and does not start a new process. So when you enter the container using multiple windows at the same time, all windows will be displayed synchronously. If one window is blocked, other windows cannot be operated on.

You can use ctrl+c to disconnect directly, but this will cause the container to exit and stop . If you want the container to continue running when you detach from the container terminal. You need to use the --sig-proxy parameter. For example:

$ docker attach --sig-proxy=false mytest

Note: When using docker attach to connect to the container's standard input and output, docker uses a memory buffer of approximately 1MB to maximize the throughput of your application. If this buffer fills up, the speed of output or writing will be affected. Therefore, to view the application logs, you can use the docker logs command.

docker logs command

docker logs [options] 容器Gets the container's logs.

For example, print the last 10 lines of the mytest application in the container.

$ docker logs --tail="10" mytest

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Implementation of modifying configuration files in Docker container
  • Implement dynamic management and monitoring of docker containers based on spring-boot and docker-java [with complete source code download]
  • Summary of methods for creating, listing, and deleting Docker containers on Linux
  • Detailed explanation of log processing of Docker containers
  • Detailed explanation of how to stop the Docker container from automatically exiting
  • Detailed explanation of how to solve the problem that the docker container cannot access the host machine through IP
  • How to use Docker container to access host network
  • Docker container operation instructions summary and detailed explanation

<<:  How to use http and WebSocket in CocosCreator

>>:  Several important MySQL variables

Recommend

Detailed explanation of several error handling when Nginx fails to start

When using Nginx as a Web server, I encountered t...

CSS scroll-snap scroll event stop and element position detection implementation

1. Scroll Snap is a must-have skill for front-end...

Detailed explanation of React setState data update mechanism

Table of contents Why use setState Usage of setSt...

Why does MySQL database index choose to use B+ tree?

Before further analyzing why MySQL database index...

Button is stretched on both sides in IE

When you write buttons (input, button), you will f...

Solutions to MySQL OOM (memory overflow)

OOM stands for "Out Of Memory", which m...

URL representation in HTML web pages

In HTML, common URLs are represented in a variety ...

How to configure nginx to return text or json

Sometimes when requesting certain interfaces, you...

Detailed tutorial on deploying Springboot or Nginx using Kubernetes

1 Introduction After "Maven deploys Springbo...

The perfect solution for forgetting the password in mysql8.0.19

Recommended reading: MySQL 8.0.19 supports accoun...