unable to process Dockerfile: unable to parse repository info: repository name component must match - asp.net

Hi I am following the guidance on this blog post, "Managing containerized ASP.NET Core apps with Kubernetes"
https://cloudplatform.googleblog.com/2016/10/managing-containerized-ASP.NET-Core-apps-with-Kubernetes.html
I am stuck at the stage where you get docker to build the image
docker build -t gcr.io/xxxx/hello-dotnet:v1 .
This is the error I am getting.
unable to process Dockerfile: unable to parse repository info: repository name component must match "[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*"
Contents of my Dockerfile are
FROM microsoft/dotnet:1:1.0.1-core
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 8080/tcp
ENV ASPNETCORE_URLS http://*:8080
ENTRYPOINT ["dotnet", "run"]

The first line of your Dockerfile should be:
FROM microsoft/dotnet:1.0.1-core

Related

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.

How to access ASP.NET Swagger API published in Docker?

I have made an ASP.NET API with scaffolding. I have generated a docker file in Visual Studio 2019:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["CoinAPI.csproj", "CoinAPI/"]
RUN dotnet restore "CoinAPI/CoinAPI.csproj"
WORKDIR "/src/CoinAPI"
COPY . .
RUN dotnet build "CoinAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "CoinAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CoinAPI.dll"]
I am building the project with command:
docker build -t coinapi .
And running it with:
docker run -dp 12344:12344 coinapi
The container is running in docker desktop in Windows, but when I access localhost:12344 I get an error 404. After adding this line of code webBuilder.UseUrls("http://localhost:12344"); in Program.cs file, I am getting an ERR_EMPTY_RESPONSE when accessing the URL. What can I do to successfully access my Swagger API run in a docker container?
The application listens to ports 80 and 443 by default, try this
docker run -dp 12344:80 coinapi
And you should access the web with http://localhost:12344
The thing that did the trick was to change webBuilder.UseUrls("http://localhost:12344"); to webBuilder.UseUrls("http://+:12344"); and now the API works and I can connect to it via the browser with http://localhost:12344/

Building ASP.NET Core API Docker Image failed in windows

I am new in Docker world. I create a simple ASP.NET Core API. I try to build a Docker image but I won't build.
This is my docker file.
FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.2-sdk-nanoserver-1803 AS build
WORKDIR /src
COPY ["FirstDemo/FirstDemo.csproj", "FirstDemo/"]
RUN dotnet restore "FirstDemo/FirstDemo.csproj"
COPY . .
WORKDIR "/src/FirstDemo"
RUN dotnet build "FirstDemo.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "FirstDemo.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "FirstDemo.dll"]
and here is my error
Step 1/17 : FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803 AS base
2.2-aspnetcore-runtime-nanoserver-1803: Pulling from microsoft/dotnet
e46172273a4e: Pull complete
68aae72b77f3: Pull complete
02db7ef764ae: Pull complete
b85c87d0746a: Pull complete
8ded5310ea16: Pull complete
50f3c06b2324: Pull complete
57b0e03264f9: Pull complete
Digest: sha256:7b0c816859dca7eeab5ae92fea96090fb37fc966622649db0567f0c752552d4a
Status: Downloaded newer image for microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803
---> 422d1790b708
Step 2/17 : WORKDIR /app
---> Running in 8ae8be6cb8c0
**re-exec error: exit status 1: output: time="2019-02-19T23:15:48-05:00" level=error msg="hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) path=\\\\?\\C:\\ProgramData\\Docker\\windowsfilter\\***** folder=C:\\ProgramData\\Docker\\tmp\\hcs815654479"
hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) path=\\?\C:\ProgramData\Docker\windowsfilter\****** folder=C:\ProgramData\Docker\tmp\hcs815654479**
I also find this question but it does not help me. Please advice me.
For those who might have the same issue.
the problem was our security application ( CHECKPOINT- ENDPOINT Security)
it blocks the access of Docker to file system. for now, we remove it, then everything is going well.

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

Asp.Net Core on Docker

I'm currently trying to launch a Docker component with a ASP.NET Core application.
I use the following repo for my test : https://github.com/aspnet/cli-samples
I ran the following commande without any issue :
git clone https://github.com/aspnet/cli-samples aspnet-Home
cd aspnet-Home/HelloWeb
cat Dockerfile
FROM microsoft/aspnetcore
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "helloweb.dll"]
sudo docker build –t helloweb .
sudo docker run -d helloweb
The image is visible using the sudo docker images, but the container doesn't launch and is not visible with sudo docker ps:
And if I browse my website, obsviously I do not see data.
Is the repo not good for my test ? Is there any mistake I do on the docker container creation ?
Running the -it command give me the following output:
The error you highlighted is because helloweb.dll you set as the ENTRYPOINT doesn't exist. There could be two reasons for it
1 You didn't build the project yet
In this case you should run dotnet restore from the project home directory, then navigate to HelloWeb directory and run dotnet publish. When I run this command, I see the following:
publish: Published to /code/HelloWeb/bin/Debug/netcoreapp1.0/publish
Published 1/1 projects successfully
2 You built the project, but the ENTRYPOINT path is wrong
COPY . . directive will copy everything from the current directory into your app directory. That means HelloWeb.dll will actually be in bin/Debug/netcoreapp1.0/publish/ (or bin/Release/... for release builds).
Option 1: Modify your entrypoint with the full path
ENTRYPOINT ["dotnet", "bin/Debug/netcoreapp1.0/publish/HelloWeb.dll"]
Your application should happily start and serve requests.
Option 2: Modify your COPY directive
Once your project has been published, everything you'll need to run it will be in the publish directory. You could copy the contents of that into the /app directory and your entrypoint will be correct. That would look like this
FROM microsoft/aspnetcore
WORKDIR /app
COPY ./bin/Debug/netcoreapp1.0/publish/ .
EXPOSE 80
ENTRYPOINT ["dotnet", "HelloWeb.dll"]
You will also probably want to add the EXPOSE directive to tell Docker that your container will be listening on port 80.
When that succeeds, you should see (if you run in interactive mode)
docker run -it helloweb
Hosting environment: Production
Content root path: /app
Now listening on: http://+:80
Application started. Press Ctrl+C to shut down.
You could also use the microsoft/dotnet:latest image instead. That image comes with the SDK installed and a very convenient run command. The Dockerfile would look like this
FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app
RUN dotnet restore
ENV ASPNETCORE_URLS http://*:5000
EXPOSE 5000
ENTRYPOINT ["dotnet", "run"]
and you should be able to modify your source and build and run your container.

Resources