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 ?
Related
I'm trying to embed tests building in docker build process and abort it in case of either of tests fail. My docker file looks like below:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
COPY ["WebApplication1.Tests/WebApplication1.Tests.csproj", "WebApplication1.Tests/"]
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR /src/WebApplication1
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS test
WORKDIR /src/WebApplication1.Tests
RUN dotnet test --logger:trx
FROM build AS publish
WORKDIR /src/WebApplication1
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Does anybody have an idea how to deal with it?
Thanks you
You have a multistage docker file, https://docs.docker.com/develop/develop-images/multistage-build/
For your case this will work
docker build --target test -t test-tag .
docker build -t webapp-image .
docker run -ti test-tag # will run tests and give you results
If you want to see output of other stages you need to do the same
Docker build only generates the docker image from your docker file. It does not run it.
You need to use "docker run" after building your image to actually start the image as a container (which will then perform your entry point command)
https://docs.docker.com/engine/reference/run/
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
I have dockerfile created by visual studio 2019.
How can i run it manually?
bellow is the dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["Client/Client.csproj", "Client/"]
RUN dotnet restore "Client/Client.csproj"
COPY . .
WORKDIR "/src/Client"
RUN dotnet build "Client.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Client.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Client.dll"]
Navigate exactly to the project folder (not solution) where the dockerfile is located.
Run the command below in terminal:
docker build -f Dockerfile ..
docker-build
Open a terminal in the folder where dockerfile is located and execute:
docker build -t image_name .
On successful build, execute:
docker run -d image_name
I advise you to read the official documentation for docker build and docker run commands. You can find additional flags which may be useful for your case.
I have successfully run "docker run". How do I browse my web app?
I have tried localhost:8000 and localhost:81 but no success.
Updated with docker ps -a
My dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["WebApplication4/WebApplication4.csproj", "WebApplication4/"]
RUN dotnet restore "WebApplication4/WebApplication4.csproj"
COPY . .
WORKDIR "/src/WebApplication4"
RUN dotnet build "WebApplication4.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebApplication4.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication4.dll"]
You are able to access localhost:52010 since the container that exposed the port 52010 is currently running, however the other containers have all exited. This is probably due to the fact that container ea7 was run with the persistent tail -f /dev/null command, while the other containers were run with the non-persistent bash command.
The reason for this could be that the image you are trying to run does not have any command that persists and as soon as the container is created all running tasks in it are completed and the container exits.
Please make sure webapplication4:dev has a persistent command in it to keep the container from exiting.
Hope this helps !
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