44

I build an image with Python installed and a Python application too. My Python application is a Hello, World! application, just printing "Hello, World!" on the screen. Dockerfile:

FROM python:2-onbuild
CMD ["python", "./helloworld.py"]

In the console I execute:

docker run xxx/zzz

I can see the Hello, World! output. Now I am trying to execute the same application, using the task from ECS. I already pulled it to Docker Hub.

How can I see the output Hello, World!? Is there a way to see that my container runs correctly?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
p.magalhaes
  • 7,595
  • 10
  • 53
  • 108

5 Answers5

59

docker logs <container id> will show you all the output of the container run. If you're running it on ECS, you'll probably need to set DOCKER_HOST=tcp://ip:port for the host that ran the container.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dnephin
  • 25,944
  • 9
  • 55
  • 45
  • 3
    My container is already stopped. Using the cmd line doing, docker run -d image, it returns me the container id. Then i can make docker logs id. But running using the ECS, i cant get this log. I really cant get the container id. – p.magalhaes Oct 12 '15 at 21:22
  • 1
    it doesn't matter if the container is stopped or running, "docker logs " will get you the output. in ECS you have to log in to each instance and do a "sudo docker ps -a" to find what you are looking for. – grayaii Apr 28 '16 at 19:26
  • @grayaii, I can not get logs from the stopped container via this command. Looking for an option, but haven't found yet. It is 2023, share it for the further readers. – Gleichmut May 02 '23 at 08:54
28

To view the logs of a Docker container in real time, use the following command:

docker logs -f <CONTAINER>

The -f or --follow option will show live log output. Also if the container is stopped it will fetch its logs.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ElasticCode
  • 7,311
  • 2
  • 34
  • 45
4

Maybe beside of tracing logs is better idea to enter into container with:

docker exec -it CONTAINER_ID /bin/sh

and investigate your process from inside.

Antal Attila
  • 588
  • 6
  • 18
0

You can log in onto your container instance and do, for example, a docker ps there.

This guide describes how to connect to your container instance:

http://docs.aws.amazon.com/AmazonECS/latest/developerguide/troubleshooting.html#instance-connect

Aurélien Bottazini
  • 3,249
  • 17
  • 26
  • The container is not running. It already stopped so I can't connect to the container. I just want to get the messages that were printed in the console. I don't know if it is possible. – p.magalhaes Oct 12 '15 at 19:03
0

You cam use basic output redirection to a file.

Whatever command you have running in your Dockerfile at the end of the command put >> /root/file.txt

So... RUN ifconfig >> /root/file.txt RUN curl google.com >> /root/file.txt

Then all you meed to do is log in to the container and type "cat /root/file.txt" to see exactly what was on screen. Is it possible to copy from container to host at end of the Dockerfile? idk but Maybe.

Michael
  • 84
  • 4