DEV Community

Flávia Bastos
Flávia Bastos

Posted on • Originally published at flaviabastos.ca on

1 1

Sending docker container logs to a separate file

In a large web application, the backend logs can get quite verbose: requests created, sent, processed, received, etc. The list can grow large very quickly depending on how logs are implemented.

You can check the logs from a Docker container using docker logs, no need to exec into the container:

docker logs <container\_id>

You can find the with docker ps and it’s not necessary to use the full ID. The first few characters is enough. So if the container id is e1215bf8014c, the command will look like:

docker logs e121

If you run docker logs you will probably see screens and more screens of logs. You can limit the logs to the last n lines with --tail:

docker logs --tail 500 <container\_id>

The command above will only display the last 500 lines. Much better.

But reading logs on the terminal is no fun so you might also want to direct the logs to a file that can be opened in the text editor, for example. To output the docker container logs to a file, run:

docker logs --tail 500 <container\_id> > mylogs.txt

_The post Sending docker container logs to a separate file was originally published at _flaviabastos.ca

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay