Search code examples
dockerlogging

How to see the logs of a docker container


I have a simple code for which I have created a docker container and the status shows it running fine. Inside the code I have used some print() commands to print the data. I wanted to see that print command output.

For this I have seen docker logs . But it seems not to be working as it shows no logs. How to check logs.?

 $ sudo docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                            NAMES
a3b3fd261b94        myfirstdocker                     "python3 ./my_script…"   22 minutes ago      Up 22 minutes                                                        elegant_darwin

 $ sudo docker logs a3b3fd261b94
 <shows nothing>

Solution

  • The first point you need to print your logs to stdout.

    To check docker logs just use the following command:

    docker logs --help
    
    Usage:  docker logs [OPTIONS] CONTAINER
    
    Fetch the logs of a container
    
    Options:
          --details        Show extra details provided to logs
      -f, --follow         Follow log output
          --help           Print usage
          --since string   Show logs since timestamp
          --tail string    Number of lines to show from the end of the logs (default "all")
      -t, --timestamps     Show timestamps
    

    Some example:

    docker logs --since=1h <container_id>