Reputation: 31
I have .NET Core 3.0 application which is running in Docker container. I want to store application logs outside the container and so i am trying to configure my docker-compose file to mount my application logs folder /app/log from container to /var/log path on my host. Here is my docker-compose file:
version: '3.4'
services:
shikimoritelegrambot:
image: ${DOCKER_REGISTRY}shikimoritelegrambot
build:
context: .
dockerfile: ShikimoriTelegramBot/Dockerfile
volumes:
- /var/log:/app/log
Here is my DOCKERFILE for project:
FROM mcr.microsoft.com/dotnet/core/runtime:3.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY ShikimoriTelegramBot/ShikimoriTelegramBot.csproj ShikimoriTelegramBot/
RUN dotnet restore ShikimoriTelegramBot/ShikimoriTelegramBot.csproj
COPY . .
WORKDIR /src/ShikimoriTelegramBot
RUN dotnet build ShikimoriTelegramBot.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish ShikimoriTelegramBot.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ShikimoriTelegramBot.dll"]
Here is link to my repository with code: https://github.com/otsomkalov/ShikimoriTelegramBot
Here is output of docker inspect command: https://pastebin.com/Dr1iMgPF
Actual result: I can see my logs in /app/log container folder. In /var/log folder of host machine logs are missing.
Expected result: I can find my logs file in /var/log folder of host machine.
Upvotes: 0
Views: 589
Reputation: 629
You need to use:
docker-compose run
instead of docker run
.
The difference is that docker-compose automatically sets up the volumes in the compose file among other things. Essentially, it is a wrapper around the docker cli.
Upvotes: 1