0

I created new Asp.net core project in VS2017, and selected docker support for linux. the docker file looks like below

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["WebApp2/WebApp2.csproj", "WebApp2/"]
RUN dotnet restore "WebApp2/WebApp2.csproj"
COPY . .
WORKDIR "/src/WebApp2"
RUN dotnet build "WebApp2.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApp2.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApp2.dll"]

When i run the below docker build command, I'm getting an error.

docker buid -t mylogin/dotnetcoreapp1 .

Error Message

Sending build context to Docker daemon  4.125MB
Step 1/16 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
 ---> 651a14e0b96b
Step 2/16 : WORKDIR /app
 ---> Running in 929f4fdb28f2
Removing intermediate container 929f4fdb28f2
 ---> 54cdd8399e5b
Step 3/16 : EXPOSE 80
 ---> Running in 844cfb6d1638
Removing intermediate container 844cfb6d1638
 ---> b15703d4c881
Step 4/16 : FROM microsoft/dotnet:2.1-sdk AS build
 ---> 1f3b89fbfa01
Step 5/16 : WORKDIR /src
 ---> Running in 07375b9916a3
Removing intermediate container 07375b9916a3
 ---> dc4227c9d5ec
Step 6/16 : COPY ["WebApp2.csproj", ""]
 ---> 1cd0239157a4
Step 7/16 : RUN dotnet restore "/WebApp2.csproj"
 ---> Running in 73fad81058fd
MSBUILD : error MSB1001: Unknown switch.
Switch: /WebApp2.csproj
    
For switch syntax, type "MSBuild /help"
The command 'cmd /S /C dotnet restore "/WebApp2.csproj"' returned a non-zero code: 1
4
  • Try using 2.2, I had the same problem with 2.1 and is solved with 2.2 Commented Mar 13, 2019 at 19:07
  • Tried updating 2.1 to 2.2 for boh sdk and dotnetcore images, but no luck.Getting the same error Commented Mar 13, 2019 at 19:24
  • Did you create new project with 2.2, with the Dockerfile from the template? I remember the old Dockerfile had wrong path. Commented Mar 13, 2019 at 19:25
  • And remember to update your Windows image to build too. As for me, I use microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803 and microsoft/dotnet:2.2-sdk-nanoserver-1803. Please try with those. Commented Mar 13, 2019 at 19:30

1 Answer 1

1

I faced the same issue, Just move the dockerfile one level up
for example your current csproj path is
c:\projects\MySolutionFolder\MyProj\MyProj.csproj (Where docker file is here as well)
Move the docker file to be in "c:\projects\MySolutionFolder\"

I hop it helps you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.