Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where is logs file kept in docker container and how to copy it?

Tags:

docker

i have a dockerfile like this.

when i docker compose up the service, i can use command to view logs.

docker test -f logs

i want to copy the logs file to my local machine.

where is the path?

docker file

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build-env
WORKDIR /app

# Copy everything else and build
COPY ./ /app/
RUN dotnet restore -r linux-musl-x64 -s http://nexus.thedevcloud.net/repository/nuget-group/
RUN dotnet publish -r linux-musl-x64 -c Release -o DrugSync/out --no-restore

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine

RUN apk add --no-cache icu-libs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false 
ENV LC_ALL=en_US.UTF-8 
ENV LANG=en_US.UTF-8 

WORKDIR /app
COPY --from=build-env /app/test/out/ /app/
ENTRYPOINT ["/app/test"]
like image 646
user2201789 Avatar asked Jan 25 '26 00:01

user2201789


1 Answers

  • Log files can be found at:

/var/lib/docker/containers/<container id>/<container id>-xxx.log

Where xxx stands for different formats based on how you have configured it.

  • You can docker inspect each container to see where their logs are:

docker inspect --format='{{.LogPath}}' $INSTANCE_ID

More details about configuring logging is here

EDIT:

  • Similar question here
  • Also I tried it on mine at it shows up:

$ docker inspect --format='{{.LogPath}}' 878eb2faac5c

/var/lib/docker/containers/878eb2faac5c9fe743fd9e9e6ba6ff7e0c3f1e02964df77e5a788dcd985c0d0b/878eb2faac5c9fe743fd9e9e6ba6ff7e0c3f1e02964df77e5a788dcd985c0d0b-json.log

Note:

On Mac machines this location would be on the VM hosting the docker containers and not on the MacOS Host.

Try screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty to access the location.

like image 119
John Avatar answered Jan 28 '26 05:01

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!