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
CodePudding user response:
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