Reputation: 827
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values",
"httpPort": 52706,
"useSSL": true,
"sslPort": 44344
}
This gives the output when it is run through visual studio
But on build, it throws error
DockerFile:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 83
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["testdocker/testdocker.csproj", "testdocker/"]
RUN dotnet restore "testdocker/testdocker.csproj"
COPY . .
WORKDIR "/src/testdocker"
RUN dotnet build "testdocker.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "testdocker.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENV ASPNETCORE_URLS http://+:83
ENTRYPOINT ["dotnet", "testdocker.dll"]
to build the docker image
docker build -t testdock .
but it gives
COPY failed: stat /var/lib/docker/tmp/docker-builder666564019/testdocker/testdocker.csproj,: no such file or directory
Please help to get the dockerfile rewritten so as to complete this build and run the app
Upvotes: 2
Views: 7439
Reputation: 191
Conceptually COPY takes path as specified in COPY command, just an example
COPY server/nginx/nginx.conf /etc/nginx/conf.d
so its necessary to run docker file from parents of server say path is like this.
xyz-app/server/nginx/nginx.conf
then you need to go to xyz-app directory and then run (And to specify docker file path use -f)
docker build -f server/nginx/Dockerfile -t app.v1.0 .
Upvotes: 0
Reputation: 29
Andrew's sample works for me.
My command:
docker build -f helloworld\dockerfile -t sr-app .
Upvotes: 0
Reputation: 1616
The fix for me appeared to be:
docker build -f PROJECT_DIR\Dockerfile .
When ran from the solution directory.
Upvotes: 1
Reputation: 239200
If you look at the Container Tools output in Visual Studio, you'll see a line like:
docker build -f "C:\Users\foo\source\MySolution\TestDocker\Dockerfile" -t testdocker:dev --target base --label "com.microsoft.created-by=visual-studio" "C:\Users\foo\source\MySolution"
When building an image for a Linux container on Windows, Docker lifts the contents of the active directory into the MobyLinux VM and all the copy commands and such are run against that path in the MobyLinux VM, not your local filesystem. Because projects very often need access to other projects in the same solution in order to build, the Dockerfiles created by Visual Studio are relative to your solution directory, such that the entire solution directory is lifted in MobyLinux.
Very likely, what you've done is navigate directly into your project directory and run the Dockerfile from there, without passing a directory to use as the "root". As such, Docker simply lifts the current, i.e your project, directory and the resulting paths in the MobyLinux VM no longer match what's in the Dockerfile.
Long and short, if you want to manually do a build of the image, then you need to ensure that the active directory that's lifted is your solution directory, not your project directory. You can achieve that simply by passing that last string of the command above to your own command, which will make it relative to your solution.
Upvotes: 2