I'm currently learning .NET core and I'm working on a Docker image for running my code in. My project is located in the ~/src/Web
where a docker-compose.yml
file is at the root of the directory structure. This file contains the following code:
version: '3.4'
services:
web:
build:
context: .
dockerfile: src/Web/Dockerfile
ports:
- 80:80
- 443:443
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_HTTPS_PORT=443
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_Kestrel__Certificates__Default__Password=localhost
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/localhost.pfx
volumes:
- ~/.aspnet/https:/https:ro
My Dockerfile, in the src/Web
directory, looks like this:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS runtime
# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
WORKDIR /app
COPY ["src/Web/Web.csproj", "src/Web/"]
RUN dotnet restore "src/Web/Web.csproj"
COPY . .
RUN dotnet build "src/Web/Web.csproj" -c Debug -o /app/build
FROM build AS publish
RUN dotnet publish "src/Web/Web.csproj" -c Debug -o /app/publish
FROM runtime as final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Web.dll"]
When I build this image, by using docker-compose up --build
it succeeds. But when whilst running the container I get the following error:
web_1 | warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
web_1 | Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
web_1 | warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
web_1 | No XML encryptor configured. Key {5e5dd257-5689-45a2-b838-01f01d53ec46} may be persisted to storage in unencrypted form.
web_1 | info: Microsoft.Hosting.Lifetime[0]
web_1 | Now listening on: https://[::]:443
web_1 | info: Microsoft.Hosting.Lifetime[0]
web_1 | Now listening on: http://[::]:80
web_1 | info: Microsoft.Hosting.Lifetime[0]
web_1 | Application started. Press Ctrl+C to shut down.
web_1 | info: Microsoft.Hosting.Lifetime[0]
web_1 | Hosting environment: Development
web_1 | info: Microsoft.Hosting.Lifetime[0]
web_1 | Content root path: /app
web_1 | npmfail: Microsoft.AspNetCore.SpaServices[0]
web_1 | npm ERR! code ENOENT
web_1 |
web_1 | fail: Microsoft.AspNetCore.SpaServices[0]
web_1 | npm ERR! syscall open
web_1 | npm ERR! path /app/Presentation/package.json
web_1 | npm ERR! errno -2
web_1 | npm ERR! enoent ENOENT: no such file or directory, open '/app/Presentation/package.json'
web_1 |
web_1 | fail: Microsoft.AspNetCore.SpaServices[0]
web_1 | npm ERR! enoent This is related to npm not being able to find a file.
web_1 | npm ERR! enoent
web_1 |
web_1 |
web_1 | fail: Microsoft.AspNetCore.SpaServices[0]
web_1 | npm ERR! A complete log of this run can be found in:
I don't understand where this is coming from, because when I tried his without Docker, and simply use the same publish command in my command line, the error doesn't appear. I also tried using different versions of Node.js.
How can I run this application within Docker without receiving this error? Also, is this a common way of setting up a development environment for working with .NET core or is dotnet run watch
only used?