Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker logs <C> returns nothing

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'?

like image 720
Kevin Burton Avatar asked Sep 21 '17 17:09

Kevin Burton


People also ask

How do I view docker logs?

First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.

How do I persist docker logs?

You can persist all container log files by creating a volume mount point to the Docker host machine or central log server. Since every container has its own unique log folder ( containerType _ containerId ), you can simply mount all container log directories (*/logs/) to the same path on your host machine.

What does Ctrl C do in docker?

Starting with docker 0.6. 5 , you can add -t to the docker run command, which will attach a pseudo-TTY . Then you can type Control-C to detach from the container without terminating it. If you use -t and -i then Control-C will terminate the container.

How do I view docker logs in Linux?

If you want to view the docker container logs, you will need to list all running containers on your docker host. You can also see the docker logs file for Nginx container located at /var/lib/docker/containers/ directory.


1 Answers

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
like image 122
tgogos Avatar answered Oct 29 '22 03:10

tgogos