Adam Matan
Adam Matan

Reputation: 136271

Containers created by docker-compose do not appear in docker ps after their termination

My problem

When a docker container started with docker run exits, it is still listed in docker ps -a and its logs can be viewed with docker logs <id>.

However, when a docker container is started using docker-compose, it only appears in docker ps and docker logs while it runs. After it exists, its logs are inaccessible.

Needless to say, I did not delete the container, neither I used --rm or any other deletion parameter.

Example

While the container is running:

$ sudo docker logs d6a06d6655b1

>  test /usr/src/what/ever/src
> ava "--match=gong*" "--verbose" "--serial"


  ✔ gong › gong_tests › gong1
...

After the container exits

$ sudo docker logs d6a06d6655b1
Error response from daemon: No such container: d6a06d6655b1

My question

How can I see the logs of exited docker containers started by docker-compose?

Update

It was a foolish mistake on my part, but in the rare case it might be relevant for others in the future:

My Makefile contained a docker-compose down command, which rm-ed the instances.

Upvotes: 2

Views: 3324

Answers (1)

larsks
larsks

Reputation: 311750

I cannot reproduce the behavior you have described. If I started with a simple docker-compose.yaml:

version: "3"

services:
  example:
    image: alpine
    command: "echo this is a test"

And then run that with docker-compose up:

Starting compose_example_1 ... 
Starting compose_example_1 ... done
Attaching to compose_example_1
example_1  | this is a test
compose_example_1 exited with code 0

The container is visible as expected in the output of docker ps -a:

CONTAINER ID        IMAGE                         COMMAND                  CREATED              STATUS                      PORTS               NAMES
929fa9ccc631        alpine                        "echo this is a te..."   About a minute ago   Exited (0) 32 seconds ago                       compose_example_1

And docker logs works without a problem:

$ docker logs compose_example_1
this is a test

If you are seeing different behavior, please update your question to include the versions of docker and docker-compose that you are working with and a specific sequence of steps that reproduce the behavior.

Upvotes: 2

Related Questions