Docker build and Github actions unable to prepare context: path "..." - asp.net

I've a weird issue with docker build in combination with GitHub actions.
The error I'm receiving is: unable to prepare context: path "..." not found Error: Process completed with exit code 1.
This error only occurs on the GitHub Actions, because when I run the same command locally on my laptop, it works fine.
cd services/Gateway/OcelotGateway
docker build -f Dockerfile ... -t stanpanman/ocelotgateway:1.0.0
Are three dots not a thing inside the RUN command, i'm so confused?
My GitHub actions:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: docker login
env:
DOCKER_USER: '${{ secrets.DOCKER_USER }}'
DOCKER_PASSWORD: '${{ secrets.DOCKER_PASSWORD }}'
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: docker build ocelotgateway
run: |
cd services/Gateway/OcelotGateway
docker build ... -t stanpanman/ocelotgateway:1.0.0
My Docker image:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Gateway/OcelotGateway/OcelotGateway.csproj", "Gateway/OcelotGateway/"]
RUN dotnet restore "Gateway/OcelotGateway/OcelotGateway.csproj"
COPY . .
WORKDIR "/src/Gateway/OcelotGateway"
RUN dotnet build "OcelotGateway.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "OcelotGateway.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "OcelotGateway.dll"]
How my file structure looks like
I've also tried to run the command:
cd services/Gateway/OcelotGateway
docker build . -t stanpanman/ocelotgateway:1.0.0
But then I'm receiving this error:
---> Running in d12aaca83aeb
COPY failed: file not found in build context or excluded by .dockerignore: stat Gateway/OcelotGateway/OcelotGateway.csproj: file does not exist
Removing intermediate container d12aaca83aeb
---> cd903f3ffb15
Step 7/17 : COPY ["Gateway/OcelotGateway/OcelotGateway.csproj", "Gateway/OcelotGateway/"]
Error: Process completed with exit code 1.
I'm quite new with Docker, I expect that something isn't correct in my file structure. Help is really, really, really appreciated!

Related

cannot access webapp running in docker

I followed a tutorial about creating a web-app using Docker. My dockerfile exposes port 5000:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 5000
#EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR .
COPY ["CustomerApi/CustomerApi.csproj", "CustomerApi/"]
COPY ["CustomerApi.Domain/CustomerApi.Domain.csproj", "CustomerApi.Domain/"]
COPY ["CustomerApi.Service/CustomerApi.Service.csproj", "CustomerApi.Service/"]
COPY ["CustomerApi.Data/CustomerApi.Data.csproj", "CustomerApi.Data/"]
RUN dotnet restore "CustomerApi/CustomerApi.csproj"
COPY . .
WORKDIR "./CustomerApi"
RUN dotnet build "CustomerApi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "CustomerApi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CustomerApi.dll"]
when I run the image locally using
docker run myrepo/demo:latest -p 5000:5000 -p 5001:5001 -e ASPNETCORE_HTTP_PORT=https://+:5001 -e ASPNETCORE_URLS=http://+:5000
and open my browser on https://localhost:5000 I get ERR_EMPTY_RESPONSE (I'm not sure why I need 5001 within my docker run-command at all, as it's not exposed within my dockerfile).
When I inspect the image within docker desktop I see this:
In particular it shows ASPNETCORE_URLS=http://+80, although I overwrote that above using -e ASPENTCORE_URLS=https://5000.
The options on docker run are split up in 2 parts:
Options before the image name are docker options
Options after the
image name override any CMD and is sent to the container
So your command should look like this
docker run -p 5000:5000 -p 5001:5001 -e ASPNETCORE_HTTP_PORT=https://+:5001 -e ASPNETCORE_URLS=http://+:5000 myrepo/demo:latest
EXPOSE doesn't actually do anything. It's mostly documentation about what ports you think the container uses. It can be wrong and if it's wrong you don't get any errors or warnings.

Docker errror: dotnet-file.dll does not exist

I have successfully builded my app and there is image listed my-app:2.7
But when I try to run it error says:
Any idea where is wrong?
docker run -it --rm -p 5000:80 --name my-app:2.7 uploadcore Unable to find image 'uploadcore:latest' locally docker: Error response from daemon: pull access denied for uploadcore, repository does not exist or may require 'docker login': denied: requested access to the resource is denied. See 'docker run --help'.
docker run -p 5000:80 my-app:2.7 Could not execute because the specified command or file was not found. Possible reasons for this include: You misspelled a built-in dotnet command. You intended to execute a .NET program, but dotnet-uploadcore.dll does not exist. You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
Dockerfile:
FROM mcr.microsoft.com/dotnet/nightly/sdk:6.0 AS base
WORKDIR /app
EXPOSE 59518
EXPOSE 44364
FROM mcr.microsoft.com/dotnet/nightly/sdk:6.0 AS build
WORKDIR /src
COPY UploadCore/UploadCore.csproj UploadCore/
RUN dotnet restore UploadCore/UploadCore.csproj
COPY . .
WORKDIR /src/UploadCore
RUN dotnet build UploadCore.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish UploadCore.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "uploadcore.dll"]
Files structure
Context
Controllers
Migrations
Models
Properties
Service
Views
wwwroot
Program.cs
Startup.cs
UploadCore.csproj
appsettings.Development.json
appsettings.json
libman.json
Linux is case sensitive, so your ENTRYPOINT has to be
ENTRYPOINT ["dotnet", "UploadCore.dll"]
Your second docker run command works. You can add a container name with the --name option like this
docker run -p 5000:80 --name mycontainer my-app:2.7
The image name has to be the first parameter that isn't an option. In your first docker run command, the first one is uploadcore, so docker looks for an image called that and it can't find it.

This site can’t be reached - Docker

I have created the Containers / Apps
But when I run it, I got this error message: This site can’t be reached. localhost unexpectedly closed the connection.
But when I run from Visual Studio, I can run it.
Extra troubleshooting steps is below
This is docker file
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["WebApplication3/WebApplication3.csproj", "WebApplication3/"]
RUN dotnet restore "WebApplication3/WebApplication3.csproj"
COPY . .
WORKDIR "/src/WebApplication3"
RUN dotnet build "WebApplication3.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication3.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication3.dll"]
By default, Swagger is only available when the app runs in development mode. Docker containers, by default, don't run in development mode.
Try accessing the API directly on http://localhost:49155/WeatherForecast
You can run the container in development mode by setting the environment variable ASPNETCORE_ENVIRONMENT to Development by adding the option -e ASPNETCORE_ENVIRONMENT=Development to your docker run command. Then Swagger should be available.

Docker fails to build in Azure Pipelines with "error MSB1001"

Am facing strange issue. When i build my Dockerfile on windows machine(Laptop) getting below error and also getting same error when i tried to deploy on Azure DevOps.
Step 7/17 : COPY ["WebApp.csproj", ""]
---> 3f3e198d00aa
Step 8/17 : RUN dotnet restore "/WebApp.csproj"
---> Running in 51f16f947ffb
MSBUILD : error MSB1001: Unknown switch.
Switch: /WebApp.csproj
For switch syntax, type "MSBuild -help"
The command '/bin/sh -c dotnet restore "/WebApp.csproj"' returned a non-zero code: 1
PS C:\Users\user\Desktop\Directory>
But the same Dockerfile works fine when we build it using visual studio it builds and starts running without any errors.
Docker file looks like:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["WebApp.csproj", ""]
RUN dotnet restore "/WebApp.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "WebApp.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebApp.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApp.dll"]
Because in your dotnet restore there is / so MSBuild think it's a switch (like /p:) and fails, you just need to remove it:
RUN dotnet restore "WebApp.csproj"

Docker for Windows building added prefix `/var/lib/docker/tmp/` for COPY?

I've installed Docker for Windows and created a new Asp.net core application with docker support using Visual Studio 2017(I haven't made any change yet). However, docker build reported the following error. Is the Dockerfile correct?
PS C:\source\repos\myProj\ProcessFiles> docker build .
Sending build context to Docker daemon 1.178MB
Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
---> 04aae08f15c5
Step 2/17 : WORKDIR /app
---> Using cache
---> 135955e04284
Step 3/17 : EXPOSE 34746
---> Using cache
---> 85fd0075aa42
Step 4/17 : EXPOSE 44398
---> Using cache
---> 7e3d5526f601
Step 5/17 : FROM microsoft/dotnet:2.1-sdk AS build
---> 7c3e298d40ac
Step 6/17 : WORKDIR /src
---> Using cache
---> b395ba27d8f9
Step 7/17 : COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/
COPY failed: stat /var/lib/docker/tmp/docker-builder662645761/ProcessFiles/ProcessFiles.csproj: no such file
or directory
Here is the Dockerfile automatically generated by Visual Studio. The error occurred on the line COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/.
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 34746
EXPOSE 44398
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/
RUN dotnet restore ProcessFiles/ProcessFiles.csproj
COPY . .
WORKDIR /src/ProcessFiles
RUN dotnet build ProcessFiles.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish ProcessFiles.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ProcessFiles.dll"]
Here is the Visual Studio output. (The lines about setting AWS were excluded).
Inspecting Dockerfile to figure how to build project and docker image
... Skip building project since it is done as part of Dockerfile
Executing docker build
... invoking 'docker build', working folder 'C:\source\repos\myProj\ProcessFiles, docker file C:\source\repos\myProc\ProcessFiles\Dockerfile, image name processfiles:latest'
... docker build: Sending build context to Docker daemon 1.178MB
... docker build: COPY failed: stat /var/lib/docker/tmp/docker-builder225959758/ProcessFiles/ProcessFiles.csproj: no such file or directory
... docker build: Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
... docker build: ---> 04aae08f15c5
... docker build: Step 2/17 : WORKDIR /app
... docker build: ---> Using cache
... docker build: ---> 135955e04284
... docker build: Step 3/17 : EXPOSE 34746
... docker build: ---> Using cache
... docker build: ---> 85fd0075aa42
... docker build: Step 4/17 : EXPOSE 44398
... docker build: ---> Using cache
... docker build: ---> 7e3d5526f601
... docker build: Step 5/17 : FROM microsoft/dotnet:2.1-sdk AS build
... docker build: ---> 7c3e298d40ac
... docker build: Step 6/17 : WORKDIR /src
... docker build: ---> Using cache
... docker build: ---> b395ba27d8f9
... docker build: Step 7/17 : COPY ProcessFiles/ProcessFiles.csproj ProcessFiles/
Error executing "docker build"
Attempting to clean up any ELB resources created for the failed deployment
Unknown error publishing container to AWS
Here are the files in directory C:\source\repos\myProj. The file Dockerfile is under C:\source\repos\myProj\ProcessFile\. Should it be moved one level up?
Mode Name
---- ----
d----- bin
d----- obj
d----- ProcessFiles
-a---- .dockerignore
-a---- .gitattributes
-a---- .gitignore
-a---- docker-compose.dcproj
-a---- docker-compose.override.yml
-a---- docker-compose.yml
-a---- myProc.sln
When you run the build command
docker build .
The . in that command indicates the "build context" that gets sent to the (possibly remote) docker engine. All of the COPY and ADD commands must be from inside this directory (or from a previous stage with multi stage builds). You can also exclude files from this context using the .dockerignore file. The tmp directory is a uniquely generated internal directory of docker's consisting of this build context.
To fix your issue, you need to make sure ProcessFiles/ProcessFiles.csproj exists in the directory where you run your build from, and that you didn't exclude it from the context with the .dockerignore file.
Edit: based on your comments, change your copy command to:
COPY ProcessFiles.csproj ProcessFiles/
Seems like VS is generating a bad dockerfile.
The answer provided BMitch is correct in my case as well, however it ends up in another error.
Short story:
Removed the project's folder from the source path in the first COPY statement
Added the project's folder to the dest path in the COPY . . statement
Long story:
https://developercommunity.visualstudio.com/content/problem/459905/docker-build-failes-with-dockerfile-created-by-vs.html

Resources