How to delete Docker container logs?

To delete the logs of a Docker container, you can follow these steps:

  1. Firstly, use the “docker ps -a” command to locate the name or ID of the container whose logs you want to delete.
  2. Run the following command to copy the container’s log file to your local machine:
docker cp <容器名称或ID>:/var/lib/docker/containers/<容器ID>/<容器ID>-json.log <本地目录>

Please replace with the name or ID of the container from which you want to delete logs, with the actual ID of the container, and with the local path where you want to save the log files.

  1. Use the following command to remove the log files of the container:
docker exec <容器名称或ID> sh -c 'truncate -s 0 /var/lib/docker/containers/<容器ID>/<容器ID>-json.log'

Please replace with the name or ID of the container that you want to delete logs from, and replace with the actual ID of the container.

  1. Finally, restart the container using the following command:
docker restart <容器名称或ID>

Please replace with the name or ID of the container you want to restart.

In this way, you have successfully deleted the logs of the Docker container.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds