We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Docker Logs

When containers are running in detached mode with the -d flag, you don't see any output in your terminal, which is nice for keeping your terminal clean, but what if something goes wrong?

Enter the docker logs command.

docker logs [OPTIONS] CONTAINER
# CONTAINER can be an id or name

Assignment

docker run -d --name logdate alpine sh -c 'while true; do echo "LOGGING: $(date)"; sleep 1; done'

The sh -c 'while true; do echo "LOGGING: $(date)"; sleep 1; done' part is just a simple shell script to execute inside the container that prints the current date and time every second.

Notice that if you run docker logs over and over again, you will get different output. That's because you're only getting the most recent logs each time.

docker logs --tail 5 CONTAINER

Run and submit the CLI tests, then stop and remove the container.