.Net Core application running on a linux container - docker

Following this link I build a .Net Core application and was able to run the application in a docker container. My host machine OS is Windows 10, and I now want to try to run the linked application in a Linux container. I have switched to Linux containers with Docker Desktop.
When I'm building the docker image I get this error:
failed to register layer: error creating overlay mount to /var/lib/docker/overlay2/f3e5279484774002c78a8eb66702c9ee7bca7038b59f4eeca7085b88dcbe25d9/merged: too many levels of symbolic links
The Dockerfile I've Used:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1903 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["NetCore.Docker/NetCore.Docker.csproj", "NetCore.Docker/"]
RUN dotnet restore "NetCore.Docker/NetCore.Docker.csproj"
COPY . .
WORKDIR "/src/NetCore.Docker"
RUN dotnet build "NetCore.Docker.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "NetCore.Docker.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "NetCore.Docker.dll"]
Thanks

reason for this is I was using wrong image, had to change the image which support linux containers

Related

Docker running dotnet command under Windows and bash under Linux

I have a pretty simple Dockerfile that builds an API image.
Dockerfile:
#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:2.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
WORKDIR /src
COPY ["MyApp.Api/MyApp.Api.csproj", "MyApp.Api/"]
COPY ["MyApp.Common/MyApp.Common.csproj", "MyApp.Common/"]
COPY ["MyApp.Service/MyApp.Service.csproj", "MyApp.Service/"]
COPY ["MyApp.Repository/MyApp.Repository.csproj", "MyApp.Repository/"]
COPY ["MyApp.Data/MyApp.Data.csproj", "MyApp.Data/"]
COPY ["MyApp.Model/MyApp.Model.csproj", "MyApp.Model/"]
COPY ["MyApp.DTO/MyApp.DTO.csproj", "MyApp.DTO/"]
RUN dotnet restore "MyApp.Api/MyApp.Api.csproj"
COPY . .
WORKDIR "/src/MyApp.Api"
RUN dotnet build "MyApp.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.Api.dll"]
Building that way : docker build -f MyApp.Api/Dockerfile -t myapp-api:latest .
Running it under Windows works fine and doing an ls /app gives all the DLL/files I expect.
I then deployed to Docker Hub and tried to run it on a dev server I have under Debian 10 hosting several other containers.
However launching the app the same way doesn't give me the same result:
4aa6c81f67a1 myapp-api:latest "bash" 8 minutes ago Exited (0) 8 minutes ago dazzling_ramanujan
Strangely enough bash appears to be launched instead of dotnet.
I then commited this exited container to a new one and overrided the entrypoint in order to inspect the container and doing an ls /app shows me an empty folder while it's filled in Windows.
Did you encounter something similar? How to debug that ?

Unable to build docker file c# - Visual Studio 2019

After creating and developing WEB Api in c#, I wanted to add docker file and run API in docker container.
My docker file is named Dockerfile, with content like this:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["WebAPI/WebAPI.csproj", "WebAPI/"]
RUN dotnet restore "WebAPI/WebAPI.csproj"
COPY . .
WORKDIR "/src/WebAPI"
RUN dotnet build "WebAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebAPI.dll"]
After building docker file, the Visual Studio code is promted this message in console:
Severity Code Description Project File Line Suppression State
Error CTC1014 Docker command failed with exit code 1.
The command 'cmd /S /C dotnet build "WebAPI.csproj" -c Release -o /app/build' returned a non-zero code: 1 WebAPI c:\devops projekti\web api gir\webapi\dockerfile 1

How to access ASP Core Web Api running in Docker using Postman

I would like to make REST calls to my ASP Core Web Api running in Docker by using Postman. Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["MyApp.API/MyApp.API.csproj", "MyApp.API/"]
RUN dotnet restore "MyApp.API/MyApp.API.csproj"
COPY . .
WORKDIR "/src/MyApp.API"
RUN dotnet build "MyApp.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.API.dll"]
Using Visual Studio 2019, I click on the Docker run button which builds the image and creates a container. However, Postman cannot access the API running in Docker. The error message is "Error: connect ECONNREFUSED 127.0.0.1:51005." Is there a port command that I should use? If so, where should I put it? Thanks.

Hosted a .net core api on windows server 2016 docker container, on invoking docker start, status is Exited (2147516566) instead of UP

I want to run multiple instances of .net core API on windows server 2016 using windows docker container. I am able to create image and container successfully, but on invoking docker start the container are not running Up instead it exited with code (2147516566).
Here is my docker file content which is in published API directory
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-sac2016
COPY / app/
ENTRYPOINT ["dotnet", "app/MyAPI.dll"]
I didn't spend long on it, but I didn't have good luck running binaries I built myself. The docker add in for visual studio always performs the build inside a container. I have adapted to this. Here is an example Dockerfile I have anonymized. Hopefully I didn't break anything:
# Base image for running final product
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-sac2016 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# build asp.net application
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-sac2016 AS build
WORKDIR /src
COPY ["Test.Docker.Windows/Test.Docker.Windows.csproj", "Test.Docker.Windows/"]
RUN dotnet restore "Test.Docker.Windows/Test.Docker.Windows.csproj"
COPY . .
WORKDIR "/src/Test.Docker.Windows"
RUN dotnet build "Test.Docker.Windows.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Test.Docker.Windows.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
# startup.bat contains dotnet test.Docker.Windows.dll
CMD ./startup.bat

Why won't this docker file run on Windows 2016 10.0.14393?

I've created an asp.net core signalr project. It builds great. Image builds fine. I publish to my private repository. However, when I try to pull the image down onto a Windows 2016 server I get an error message: docker : a Windows version 10.0.17134-based image is incompatible with a 10.0.14393 host
I don't see where I'm targeting a specific platform, and the research that I've done seems like this should run
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /app
COPY ./*.csproj ./EntityStatusChangeService/
RUN dotnet restore ./EntityStatusChangeService/EntityStatusChangeService.csproj
COPY ./. ./EntityStatusChangeService/
WORKDIR /app/EntityStatusChangeService
RUN dotnet publish -c Release -o out
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS runtime
WORKDIR /app
COPY --from=build /app/EntityStatusChangeService/out ./
ENTRYPOINT ["dotnet", "EntityStatusChangeService.dll"]

Resources