Your dockerfile should look like below:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
WORKDIR /app
COPY . .
RUN dotnet publish -c Release
WORKDIR /app
ENTRYPOINT ["dotnet", "run"]
[Edited by gewarren to add document details]
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@OneBlueBird Thanks for logging an issue. Are you referring to this page? https://docs.microsoft.com/en-us/dotnet/architecture/microservices/docker-application-development-process/docker-app-development-workflow
Nope. I will share it..give me some time
On Tue, Apr 21, 2020 at 12:45 AM Genevieve Warren notifications@github.com
wrote:
@OneBlueBird https://github.com/OneBlueBird Thanks for logging an
issue. Are you referring to this page?
https://docs.microsoft.com/en-us/dotnet/architecture/microservices/docker-application-development-process/docker-app-development-workflow—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dotnet/docs/issues/17942#issuecomment-616754532, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AITEMO7LI5OSPM42WKDXSYLRNSNMBANCNFSM4MLZN7ZA
.
Hi,
Good Day. I was referring page from below link:
https://docs.microsoft.com/en-us/dotnet/core/docker/build-container#feedback
Please try to improvise as it needs to help a developer like us to learn
and appreciate it.
Thank you
Saravanakumar
On Tue, Apr 21, 2020 at 12:45 AM Genevieve Warren notifications@github.com
wrote:
@OneBlueBird https://github.com/OneBlueBird Thanks for logging an
issue. Are you referring to this page?
https://docs.microsoft.com/en-us/dotnet/architecture/microservices/docker-application-development-process/docker-app-development-workflow—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dotnet/docs/issues/17942#issuecomment-616754532, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AITEMO7LI5OSPM42WKDXSYLRNSNMBANCNFSM4MLZN7ZA
.
Hello. I think adding WORKDIR is good for the entry point but I don't think copying all of the app into the container is good.
Hi,
The instructions were not at all clear for a nee developer to take it and
run AS-IS. I didn't find it useful to take the instructions given in the
page as its useless!
On Thu, Apr 23, 2020 at 11:29 PM Andy De George notifications@github.com
wrote:
Hello. I think adding WORKDIR is good for the entry point but I don't
think copying all of the app into the container is good.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dotnet/docs/issues/17942#issuecomment-618553442, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AITEMOYB5UANT5YCTILXCJLROB6Y5ANCNFSM4MLZN7ZA
.
I'm sorry this article isn't helping you. I took some time to look into the feedback posted through the website and I only came up with 5 from the last 90 days and they were all positive saying how this helped them as a new user.
With your suggestion, I'm not sure what it is adding except compiling within the container itself. I'm not sure what more that adds to the article except moving one step from outside the container to inside the container.
Perhaps you can explain more about your reasoning?
Okay. As a new developer, if I were to try and understand how to write a Dockerfile for a given .NET core console apps from the link https://docs.microsoft.com/en-us/dotnet/core/docker/build-container, hardly I can only see only below lines as given below:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
COPY app/bin/Release/netcoreapp3.1/publish/ app/
ENTRYPOINT ["dotnet", "app/myapp.dll"]
After creating the docker image, I am not able to create a runable container. Let me show steps that are not convincing here to me:
docker build -t myimage -f Dockerfile .
Create a container
Check the running container
docker start vibrant_ganguly
--> Displays vibrant_ganguly
docker ps -a
--> Exited (0) x seconds ago !
@OneBlueBird Hello. Can you share the following information?
tree and paste the output?Thanks!
Windows 10 Enterprise with Docker Hub Installed
Program.cs below:
using System;
namespace myapp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Microsoft Windows [Version 10.0.18362.720]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Windows\system32>d:
D:>cd D:\skdotnetcoretest
D:\skdotnetcoretest>tree
Folder PATH listing
Volume serial number is 042E-2ED1
D:.
└───app
├───bin
│ ├───Debug
│ │ └───netcoreapp3.1
│ └───Release
│ └───netcoreapp3.1
│ └───publish
└───obj
├───Debug
│ └───netcoreapp3.1
└───Release
└───netcoreapp3.1
D:\skdotnetcoretest>
Ahh I think I found your problem :) The way docker works is that if the process container runs (the app) ends, the container shuts down. This is why the sample app at the start of the article is a loop that prints.
Your code below will print "Hello World" and then quit. That stops the container and the container status is: Exited (0) x seconds ago
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
Change your app to the following from the tutorial article:
using System;
namespace myapp
{
class Program
{
static void Main(string[] args)
{
var counter = 0;
var max = args.Length != 0 ? Convert.ToInt32(args[0]) : -1;
while (max == -1 || counter < max)
{
counter++;
Console.WriteLine($"Counter: {counter}");
System.Threading.Tasks.Task.Delay(1000).Wait();
}
}
}
}
I want to make it simple here. I just want to run a Hello World program. It seems, the code in the docs website uses brute force techniques to make Docker run(for the sake of making it run). Any Docker sample that we run today to run Hello World program need not have these unnecessary loops.
@OneBlueBird Gotcha! Thank you for the feedback.
@IEvangelist has taken over the article. My initial thought is to close this feedback. The article is currently designed to show an app running inside of the container and then how to interact with the container through docker. If the app immediately stops, you can't do that.
Hi @OneBlueBird,
If you're Program.cs is a simple Console.WriteLine it exits immediately. If so, that is fine - however; this tutorial exemplifies a few more capabilities, that require the executable to remain running. With that said, if you want to see "Hello World" print from a container, run the following command with your app:
docker run -it --rm [image name]
This will print "Hello World" to the console, and then remove the container when done - which happens instantly. For the tutorial, we're going to leave it as is. Does this help?
I just verified this locally with my named image counter-image:
docker run -it --rm counter-image
Hello World, from .NET Core app!
And the following C#:
using System;
namespace NetCore.Docker
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World, from .NET Core app!");
}
}
}
Hi @OneBlueBird - I'm going to close this issue for now. If you would like more assistance with this, please follow up here and we'll have another look. I believe I was able to help you out with the details here. Thank you