docker logs <C> returns nothing

12,444

Docker containers exit when their main process finishes. That is why you don't get any logs.

The docker logs command batch-retrieves logs present at the time of execution.

(see: https://docs.docker.com/engine/reference/commandline/logs/)

An example:

The following will create a new container and start it:

docker run -d --name=my_test_container alpine ping -c 20 127.0.0.1
[----run----]   [--------name--------] [image][-----command------]

Try to use the following, before ping command stops:

  • docker logs my_test_container
  • docker logs --follow my_test_container

The first one shows what has been printed out by ping (until then) and the second one gives you logs as ping prints out new lines.

After 20 ping requests, the ping command finishes and the container stops.

ubuntu@ubuntu:~$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
e8f371000146        alpine              "ping -c 20 127.0.0.1"   29 seconds ago      Exited (0) 9 seconds ago                       my_test_container
Share:
12,444
Kevin Burton
Author by

Kevin Burton

Updated on July 20, 2022

Comments

  • Kevin Burton
    Kevin Burton almost 2 years

    I build and run a docker image with

    docker run --detach --name api rkevinburton/myagsourceapi
    

    But when I 'docker ps -a' I get a message that this container has exited.

    CONTAINER ID        IMAGE                        COMMAND             CREATED             STATUS                     PORTS               NAMES
    ee956fbf1d7f        rkevinburton/myagsourceapi   "/bin/bash"         10 seconds ago      Exited (0) 8 seconds ago                       api
    

    So I want to find out why it exited. So I issue the command

    docker logs ee
    

    But this command returns nothing. As the docker host is a Windows machine I looked on ~\AppData\Local\Docker but the information in the log*.txt or install-log.* didn't seem to help me any. How can I get more information on why the container 'Exited'?