A dotnet hello world console app running in a container based upon anthonyharrison/pi-dotnet:0.2
488
This tutorial presumes that you know the following commands:
dotnet new consoledotnet build .dotnet publish .This image is built from the following Dockerfile:
FROM anthonyharrison/pi-dotnet:0.2 as builder
WORKDIR /app
RUN /root/.dotnet/dotnet new console # this creates a default project in /app that when run outputs 'Hello World'
RUN /root/.dotnet/dotnet build . # this builds the default project in /app
RUN /root/.dotnet/dotnet publish . # this publishes all of the artefacts to a single directory in /app/bin
RUN mv /app/bin/Debug/netcoreapp2.2/publish/* /app/bin # this moves the artefacts from the default publish directory at /app/bin/Debug/netcoreapp2.2/publish to a user-chosen location, in this case the existing /app/bin
# NOTE: using multiple run statements is not best practice however are used here for illustrative purposes, and this is because it creates multiple build steps. A better practice would be to have them all being run from a single run command.
To build that Dockerfile, you jut change into the directory that the Dockerfile is in and go docker build . (don't forget the trailing dot!) If you want, create a file in a directory by itself and call it Dockerfile. Then just do the above command, go docker images to see what was built, and then treat it below! Alternatively, just pull this image because it is already built!
When the Dockerfile is built, the result is an app at /app/bin/app.dll, complete with published supporting artefacts.
To run the app, you have to create a container for it, for example, using:
docker run -it --name mycontainername anthonyharrison/pi-dotnet-console-helloworld:0.1
Then, when it launches in interactive mode from the command line, you have to run:
/root/.docker/docker /app/bin/app.dll (n.b., the dotnet executable is not in the environment $PATH so it's path has to be fully qualified)
The result is the following output on the command line:
Hello World (n.b. this is because this is the default output of a dotnet new console app)
To view all of the artefacts created by this Dockerfile, create a container as shown above and examine the /app directory and it's sub-directories.
As the image anthonyharrison/pi-dotnet:0.2 includes git, you should be able to replace the line RUN /root/.dotnet/dotnet new console with RUN git clone {path to clone} and then adjust the following build and publish lines to build and publish the code that you cloned from the git repository!
Keep in mind that the path to dotnet is not in the $PATH so you have to use the fully qualified path.
Content type
Image
Digest
Size
319.9 MB
Last updated
about 7 years ago
docker pull anthonyharrison/pi-dotnet-console-helloworld