What is the method for cleaning up container logs in Docker?
要清理Docker容器的日志,可以使用以下步骤:
- Access the Docker host and use the following command to view the IDs of all containers:
- List all containers, including stopped ones, and only display their container IDs.
- View the log file paths for all containers using the following command:
- Retrieve the log path of the container with the specified ID using the “docker inspect” command.
- Clear the logs of the container using the following command:
- Limit the size of /var/lib/docker/containers/CONTAINER_ID/CONTAINER_ID-json.log file to zero.
Please note that the CONTAINER_ID in the command above needs to be replaced with the actual container ID. Additionally, clearing the log file will reduce its size to 0 but will not delete the file, so if you need to completely remove the log file, you can use the rm command to delete it.