Reputation: 3879
After right clicking on my web api .NET Core 2.2 in Visual Studio 2019, and creating a Dockerfile
, I found I am unable to manually do a docker build
with a name and tag. What I get is a huge image (about 1.8gb) with <none>
and <none>
as an ID and tag.
These are the steps:
After creating the file, I run Docker from VS and that then creates this image: Snowdon...:dev
(260mb). However, when I deploy this to Azure, the container terminates immediately.
If I run the image with another image using docker-compose
this then creates a new image: Snowdon...:latest
(269mb), then if I deploy this to Azure it works fine.
So, although I have this working in the cloud, I was wondering why I can't just do a docker build
?
Here is the Dockerfile
for my web api:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["SnowdonAPI_05/SnowdonAPI_05.csproj", "SnowdonAPI_05/"]
RUN dotnet restore "SnowdonAPI_05/SnowdonAPI_05.csproj"
COPY . .
WORKDIR "/src/SnowdonAPI_05"
RUN dotnet build "SnowdonAPI_05.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "SnowdonAPI_05.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SnowdonAPI_05.dll"]
I am calling build
from here:
Upvotes: 2
Views: 1243
Reputation: 16198
To make this a solution for anybody else who comes across this:
If you manually want to run docker build
on this, you need to execute this from the folder where your solution file (.sln
) is located. So like this then:
docker build -f project\folder\Dockerfile -t mytag:1.0 .
Upvotes: 6