Joseph Adam
Joseph Adam

Reputation: 1642

how to save the logs for docker-compose up -d --build

The logs are printed on the console when I do docker-compose up -d --build, how can I have them saved to a file so I can go through the logs?

These logs

0.0s  => => transferring dockerfile: 771B                                                                            
0.0s  => [internal] load .dockerignore                                                                               
0.0s  => => transferring context: 2B                                                                                 
0.0s  => [internal] load metadata for docker.io/library/python:3.8.12-bullseye                                       
1.5s  => [auth] library/python:pull token for registry-1.docker.io                                                   
0.0s  => [internal] load build context                                                                               
2.0s  => => transferring context: 847.24kB                                                                           
1.9s  => [1/7] FROM docker.io/library/python:3.8.12-bullseye@sha256:b39ab988ac2fa749273cf6fdeb89fb3635850824419dc61  
0.0s  => => resolve docker.io/library/python:3.8.12-bullseye@sha256:b39ab988ac2fa749273cf6fdeb89fb3635850824419dc61  
0.0s  =>   CACHED [2/7] WORKDIR /usr/src/app

Upvotes: 10

Views: 17747

Answers (3)

Xanatos
Xanatos

Reputation: 1626

As mentioned in a different answer, the --progress flag works if you are doing a docker compose build.

But in your question, you are doing docker compose up, where --progress doesn't work. In that case, to get full plain text output to the terminal do something this:

DOCKER_BUILDKIT=0 docker compose up -d --build

Source: Enable "progress plain" in docker-compose file

Upvotes: 2

dpooley
dpooley

Reputation: 131

This can be achieved using docker-compose build and the --progress flag and specifying one of the following options: auto, tty, plain, or quiet (default "auto")

So to persist the logs in your terminal you would build with:

docker-compose build --progress plain

See --help:

 $ docker-compose build --help

Usage:  docker compose build [OPTIONS] [SERVICE...]

Build or rebuild services

Options:
      --build-arg stringArray   Set build-time variables for services.
      --no-cache                Do not use cache when building the image
      --progress string         Set type of progress output (auto, tty, plain, quiet) (default "auto")
      --pull                    Always attempt to pull a newer version of the image.
  -q, --quiet                   Don't print anything to STDOUT
      --ssh string              Set SSH authentications used when building service images. (use
                                'default' for using your default SSH Agent)

Upvotes: 13

Le Rilleur
Le Rilleur

Reputation: 245

Docker already saves the logs in a json file. To find it you can do

docker inspect --format='{{.LogPath}}' [container id]

Or if you just want the outputs of the docker logs function just do this :

docker-compose logs --no-color > logs.txt

For docker-compose up --build, did you try that :

docker-compose up --build &> logs.txt

Upvotes: 8

Related Questions