1

First I create an image of project then create container then I want to start it but after starting the container it exits . why it says " Exited (145) 2 seconds ago " for started container? check the image

exited

I did what @Jamie said this is the result :

PM> docker run myimage -d
docker : Did you mean to run dotnet SDK commands? Please install dotnet SDK 
from:
At line:1 char:1
+ docker run myimage -d
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (Did you mean to...otnet SDK 
from::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

 https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

DockerFile :

enter image description here

I am using this tutorial : This

I did what @Pierre said . this is the result (No change) enter image description here

iDeveloper
  • 1,699
  • 22
  • 47
  • 2
    If you were to run the image with the `docker run myimage -d` (i.e. without detaching) rather than using the `docker start` command, you'll see any text which is output to the console within the container. This will give you clues as to why the container stopped. – Jamie Taylor Jul 03 '19 at 11:03
  • 1
    check the question please i modified it . @JamieTaylor – iDeveloper Jul 03 '19 at 11:07
  • 1
    I am using this tutorial to host a .net core project in docker: https://learn.microsoft.com/en-us/dotnet/core/docker/build-container – iDeveloper Jul 03 '19 at 11:09
  • Can you show your Dockerfile? – Pierre B. Jul 03 '19 at 11:15
  • 2
    From the output, it looks like you are using a runtime image, but calling an SDK command. as @PierreB. said, could you share your dockerfile? – Jamie Taylor Jul 03 '19 at 11:18
  • this is my docker file @JamieTaylor : FROM mcr.microsoft.com/dotnet/core/runtime:2.2 ENTRYPOINT ["dotnet", "app/app4.dll"] – iDeveloper Jul 03 '19 at 11:35
  • 2
    Add it to the question by editing ;) – Pierre B. Jul 03 '19 at 11:39
  • sure I am doing it .. – iDeveloper Jul 03 '19 at 11:43
  • In your screen shot, Visual Studio is showing that you are building in debug mode (the select next to the run button [looks like a green play button]) have you performed a publish of your app in Release mode? The docker file you are referencing copies files from the default output path from a publish in Release mode. – Jamie Taylor Jul 03 '19 at 12:38

2 Answers2

2

You are missing the part where you need to copy the files into Docker image as shown in the tutorial you are following before ENTRYPOINT:

COPY app/bin/Release/netcoreapp2.2/publish/ app/
Pierre B.
  • 11,612
  • 1
  • 37
  • 58
0

the issue was related to my docker file :

I created another project I followed this tutorial :tutorial

I used the docker file in mentioned link and modified it a little bit based on my project needs.

  FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1709 AS base
  WORKDIR /app
  EXPOSE 80
  EXPOSE 443

  FROM microsoft/dotnet:2.2-sdk-nanoserver-1709 AS build
  WORKDIR /src
  COPY ./wa2.csproj ./
  RUN dotnet restore
  COPY . .
  WORKDIR /src
  RUN dotnet build -c Release -o /app

  FROM build AS publish
  RUN dotnet publish -c Release -o /app

  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app .
  ENTRYPOINT ["dotnet", "wa2.dll"]

Then I created image from project

  $ docker build -t myimage2 -f Dockerfile .

(I had to switch to windows container from docker as mentioned here

I faced a weird error which will be solved by help of this link (By the way, VPN was also Off)

The mentioned error on building image. This is the error line "RUN dotnet restor"

here

then I executed these two line on command in project folder

// create container

 $ docker build -t (project name) .

// run container

 $ docker run -d -p 8080:80 --name (container name) (project name)

the container is created and I could run it. then I could see the result from 2 port one from Visual studio another from Docker

image

iDeveloper
  • 1,699
  • 22
  • 47