I have a web project that is written on the top of the ASP.NET Core 3.1 framework. I want to run the project in a docker container on a Linux virtual box.
I create the following docker-compose.yml
file
version: '3.4'
services:
myproject:
image: ${DOCKER_REGISTRY-}myproject
build:
context: .
dockerfile: myproject/Dockerfile
volumes:
- storage:/storage
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- 51736:80
- 44344:443
volumes:
storage:
When I execute docker-compose up --build
I get the following output
Successfully built b084cb989f05
Successfully tagged myproject:latest
Starting myproject_myproject_1 ... done
Attaching to myproject_myproject_1
myproject_1 | Unhandled exception. System.IO.DirectoryNotFoundException: /app/Storage/
myproject_1 | at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
myproject_1 | at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
From the logs above the app is looking for /app/Storage/
path to initialize the PhysicalFileProvider
. I am not sure where that is coming from. According to my docker-compose.yml
file, the storage volume should me /storage
not /app/Storage/
.
At some point, I had storage:/app/Storage
in my docker-compose.yml
file but it is no longer there. What could be causing the image to attach the wrong volume/storage folder?
Updated
Here is the content of the Dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["myproject/myproject.csproj", "myproject/"]
RUN dotnet restore "myproject/myproject.csproj"
COPY . .
WORKDIR "/src/myproject"
RUN dotnet build "myproject.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "myproject.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "myproject.dll"]
I tried the following command to delete everything
docker-compose down -v --rmi all --remove-orphans
docker-compose build --no-cache
However, I am still getting the same result. How can I correctly mount the /storage
folder with the image?
The message is not related to docker-compose I think.
Something in the application is telling it to look at that folder. It's correct that the folder doesn't exist because the docker-compose doesn't create it.
Check the code or config in the ASP.NET application itself that provides this path. Or the docker command that runs the dotnet process als, or the environment variables set in the dockerfile.
Looking at your dockerfile, I'm guessing the app is looking for storage
only not /storage
(relative path not absolute path), and that's why you are getting the extra /app
in the beginning (from the workdir
).