Skip to main content

Step-by-step example to create an ASP.NET Core on Docker sample.

title: "Step by step: ASP.NET Core on Docker"
author: Carlos Mendible
date: September 26, 2016

This week I have to give an introductory talk on DevOps and
[Docker]( and therefore I decided to prepare a simple
**Step by step: ASP.NET Core on [Docker](** sample.

Assuming you have [Docker]( installed and running,
follow these 4 simple steps:

## 1. Create a Dockerfile

On your Docker box create a `Dockerfile` with the following contents:

# We use the microsoft/dotnet image as a starting point.
FROM microsoft/dotnet

# Install git
RUN apt-get install git -y

# Create a folder to clone our source code
RUN mkdir repositories

# Set our working folder
WORKDIR repositories

# Clone the source code
RUN git clone

# Set our working folder
WORKDIR aspnet-core-helloworld/src/dotnetstarter

# Expose port 5000 for the application.

# Restore nuget packages
RUN dotnet restore

# Start the application using dotnet!!!
ENTRYPOINT dotnet run

## 2. Create a docker image

With the `Dockerfile` in place, run the following command:

sudo docker build -t hello_world .

Now you have an image named `hello_world` with all the dependencies and code
needed to run the sample.

## 3. Test the Docker image

To test the Docker image run the following command:

docker run -it -p 5000:5000 hello_world

If everything runs as expected you can head to your browser and navigate to
<http://localhost:5000> and confirm that the application is running!

## 4. Run the Docker image as a daemon process

Now that you know that everything is working as expected use the following
command to run the Docker image as a daemon process:

docker run -t -d -p 5000:5000 hello_world

Feel free to logout or close the connection with your Docker box and the
application will keep running.

You can get a copy of the [docker file here](

Hope it helps!