This assumes you have installed Docker on Linux, Docker is running, and that you have created a container. The docker logs command is used to view a containers logs. You may want to first issue the docker ps command to get the name of the containers.
The docker ps command can be used to determine if the container is running.
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d937372c09ab9 b939aa938add9913 "/docker-entrypoin..." 6 minutes ago Created my-container
In this example, the logs for the container named my-container will be displayed.
docker logs my-container
The --follow option can be used to watch the logs in real time.
docker logs my-container --follow
The -t or --timestamps option can be included to include the datetime in the output.
docker logs --timestamps my-container
The --since and --until options can be included to only show events within a specified datetime.
docker logs --since 2020-11-14T08:00:00 --until 2020-11-14T11:00:00 my-container
The --tail=10 option can be included to only list the last 10 messages in the log.
docker logs --tail=10 2020-11-14 my-container
You may need to use 2>&1 to grep the logs.
docker logs my-container 2>&1 | grep foo