How to view Docker logs to troubleshoot containers

If you happen to deploy containers with Docker, sooner or later you will have to troubleshoot. Jack Wallen exhibits you the way to take action with the logs command.

docker-with-waves.jpg

Illustration: Lisa Hornung/TechRepublic

Containers generally is a tough resolution to deploy and handle. Given there are such a lot of transferring items to this puzzle, it is typically very difficult to even know the place to start when hassle strikes. Is it the host? What concerning the community? Possibly it is the supplier? Or perhaps it is only a container that is gone awry.

After you have discovered nothing flawed along with your host, community, or supplier, it is time to have a look at what might be most frequently the basis reason for the issue…the container itself.

Though containers have turn into the darling of the IT ball, they’re removed from good. Issues go flawed. And given how sophisticated containers are, they typically go flawed on the very coronary heart of your deployments.

SEE: Guidelines: Server stock (TechRepublic Premium)

So what do you do? How do you troubleshoot a single container? Fortuitously, the builders thought of that and added a command that means that you can verify the logs of a container. Let’s learn the way to make use of this helpful software.

What you will want

The one factor you will have to view Docker container logs is Docker deployed to a machine. It would not matter what the platform is, as long as it helps Docker. I will be demonstrating on Ubuntu Server 20.04.

With that single requisite out of the best way, let’s view these logs.

Easy methods to use the Docker log command

I will deploy an NGINX container to show how container logs are considered. So log into your Docker host and deploy the NGINX container with the command:

docker run --name docker-nginx -p 8080:80 -d nginx

Give it a second and you need to have a brand new NGINX container operating, named docker-nginx. Open an online browser and level it to http://SERVER:8080 (The place SERVER is the IP tackle of the internet hosting server) and you need to see the NGINX welcome web page.

However to illustrate that web page would not seem? What offers? Why is my container not operating? To seek out out, we would difficulty the command:

docker logs docker-nginx

Docker will instantly print out the entire log file data it has (Determine A).

Determine A

dockerlogsb.jpg

The Docker logs of our newly deployed NGINX container.

In fact, our container would not have any errors, as a result of it is operating simply advantageous. Even so, that is plenty of output to comb via. As an instance you solely need to view the final 5 strains from the log file. For that you could possibly difficulty the command:

docker logs docker-nginx --tail 5

Or perhaps you need to view the logs as they’re written (so you possibly can extra simply troubleshoot a container because it sends and receives knowledge). For that you’ll use the observe possibility like so:

docker logs docker-nginx --follow

It will proceed outputting data, so you possibly can watch the logs being written in actual time (Determine B).

Determine B

dockerlogse.jpg

Following the Docker log file for our operating docker-nginx container.

As an instance you already know one thing went flawed inside the final hour and also you need to solely view the logs which were written inside that timeframe. For that, difficulty the command:

docker logs docker-nginx --since=60m

Or perhaps you already know one thing went flawed previous to an hour in the past. You should utilize the till choice to show each log file written prior with the command:

docker logs docker-nginx --until=60m

Lastly, you would possibly need to add a number of additional particulars to your log output, which is completed with the –details possibility:

docker logs docker-nginx --details

Between these instructions, you need to have every part that you must troubleshoot a selected Docker container. One factor to notice is which you can substitute the Container ID for the Title (as I’ve used above). To seek out the related Container ID, difficulty the command:

docker ps -a

While you run the docker logs command utilizing the Container ID, you solely want to make use of the primary 4 characters of the ID, as in:

docker logs 118b --details

And that is all there may be to viewing the logs of your Docker containers.

Additionally see

Recent Articles

spot_img

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox