How to check logs of docker container?

check logs of docker container

In order to get logs of docker container, we can use this command –

docker logs <container_id>

Or,

docker logs <container_name>

For our example of mongodb, let’s first run a container –

docker run -d --name mongo-container mongo
running mongo container

Now let’s check which containers are running –

docker ps
checking which containers are running

We can see that our mongo container is running under the name mongo-container. To get the logs of this container –

docker logs mongo-container

or we can use the container id –

docker logs 6bd3e72
getting logs of the mongo container