I use docker logs [container-name] to see the logs of a specific container.
Is there an elegant way to clear these logs?
Here is a cross platform solution to clearing docker container logs:
docker run --rm -v /var/lib/docker:/var/lib/docker alpine sh -c "echo '' > $(docker inspect --format='{{.LogPath}}' CONTAINER_NAME)"
Paste this into your terminal and change CONTAINER_NAME to desired container name or id.
Use:
truncate -s 0 /var/lib/docker/containers/*/*-json.log
You may need sudo
sudo sh -c "truncate -s 0 /var/lib/docker/containers/*/*-json.log"
ref. Jeff S. How to clear the logs properly for a Docker container?
Reference: Truncating a file while it's being used (Linux)
On Docker for Windows and Mac, and probably others too, it is possible to use the tail option. For example:
docker logs -f --tail 100
This way, only the last 100 lines are shown, and you don't have first to scroll through 1M lines...
(And thus, deleting the log is probably unnecessary)