Getting console output from a Docker container
Solution 1
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.
Solution 2
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.
Solution 3
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.
p.magalhaes
Updated on February 19, 2022Comments
-
p.magalhaes about 2 years
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?
-
p.magalhaes over 8 yearsThe 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 over 8 yearsMy 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.
-
grayaii about 8 yearsit doesn't matter if the container is stopped or running, "docker logs <container id>" 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.