How to delete Docker container logs?
To delete the logs of a Docker container, you can follow these steps:
- Firstly, use the “docker ps -a” command to locate the name or ID of the container whose logs you want to delete.
- 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
- 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
- Finally, restart the container using the following command:
docker restart <容器名称或ID>
Please replace
In this way, you have successfully deleted the logs of the Docker container.