Docker Container logs

If are running your container in -d (detached mode) or by docker remote API, you will not see any logs in the console. To access the logs of the running container you need to use the docker logs command.

To see docker containers logs make sure that first of all, docker container is running you can check this by using-

learning-ocean:~ gaurav$ docker container ls
CONTAINER ID  IMAGE     COMMAND         CREATED     STATUS     PORTS                      NAMES

learning-ocean:~ gaurav$ docker container run -itd nginx
bc2cb9f905ffb3b94281cf4d134d3c9c720af8730fbc27ab3e0d8f001e1a76e5

learning-ocean:~ gaurav$ docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS              NAMES
bc2cb9f905ff   nginx          "/docker-entrypoint.…"   35 seconds ago   Up 34 seconds   80/tcp            thirsty_dijkstra

To see all the logs of a particular container

syntex

docker container logs ContainerName/ContainerID

In our example, we will see the logs of the NGINX container-

learning-ocean:~ gaurav$ docker container logs bc
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/07/02 04:27:05 [notice] 1#1: using the "epoll" event method
2021/07/02 04:27:05 [notice] 1#1: nginx/1.21.0
2021/07/02 04:27:05 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
2021/07/02 04:27:05 [notice] 1#1: OS: Linux 5.10.25-linuxkit
2021/07/02 04:27:05 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/07/02 04:27:05 [notice] 1#1: start worker processes
2021/07/02 04:27:05 [notice] 1#1: start worker process 32
2021/07/02 04:27:05 [notice] 1#1: start worker process 33
learning-ocean:~ gaurav$

Options:

-f --follow Follow log output ( if you want to see logs continuously)
learning-ocean:~ gaurav$ docker container logs -f bc
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/07/02 04:27:05 [notice] 1#1: using the "epoll" event method
2021/07/02 04:27:05 [notice] 1#1: nginx/1.21.0
2021/07/02 04:27:05 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
2021/07/02 04:27:05 [notice] 1#1: OS: Linux 5.10.25-linuxkit
2021/07/02 04:27:05 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/07/02 04:27:05 [notice] 1#1: start worker processes
2021/07/02 04:27:05 [notice] 1#1: start worker process 32
2021/07/02 04:27:05 [notice] 1#1: start worker process 33