However, it’s a cheap and straightforward strategy to help you get started. Using a syslog server might not be the first option you think of when you think about collecting container logs. You’ll notice, though, there’s going to be a missing piece once logs are there-I’ll come back to this later. There are many ways you can process and retain Docker container logs. We need a better way to collect container logs, so we don’t lose them when the container stops-containers come and go all the time. This command only works while the container is running. However, if the container goes away, you can’t read its logs anymore using the logs command. That’s initially good because you can read the logs from a container. See below for an example of the commands you’d usually run: $ docker psĬONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESģ40461436e07 busybox "/bin/sh -c 'i=0 wh…" 7 seconds ago Up 7 seconds fervent_shtern Then, you can read the logs with the docker logs CONTAINER, and you can add the -f flag to see logs live.
If you want to read the logs from that container, you need either the name or the ID of the container. docker run -d busybox /bin/sh -c 'i=0 while true do echo "$i: $(date)" i=$((i+1)) sleep 1 done' The following command runs a container that simply prints a text indefinitely.
Reading Logs From a Containerĭocker comes with a native command, docker logs, to read logs from a container.
Then, I’ll show you how you can integrate syslog and Docker to improve your troubleshooting strategy through logs. In this post, I’ll provide a quick overview of why having a syslog server might be a good option. Also, if the container has gone away, we can read the logs collected while it was running. We need to have a centralized location for our logs to have a better context of the problem. However, we live in a world where we won’t have only one container running, and our systems have multiple dependencies.