Today I’ll show you how to Run ASP.NET Core on OpenShift.

First be aware of the following prerequisites:

  • You’ll need a working Docker installation. If you are using Windows 10 you can get Docker for Windows here.
  • Be sure to Disable TLS for for your Docker installation
  • Be sure to set as an Insecure Registry in your Docker installation
  • Be sure to set as a Registry Mirror in your Docker installation
  • You’ll need download the oc Client Tools

Note: If you want to learn about OpenShift and what can you do with it, I recommend the free book: Openshift for Developers.

Now let’s start:

1. Create a folder for your new project#

Open a command promt an run:

1mkdir aspnet.on.openshift

2. Create the project#

1cd aspnet.on.openshift
2dotnet new web

No you have a working Hello World application.

3. Publish your application#

Restore the nuget packages and publish your application with the following commands:

1dotnet restore
2dotnet publish -c release

4. Create a Dockerfile#

Create a Dockerfile (be aware of the capital D) with the following contents:

 1FROM microsoft/dotnet 
 4ENV ASPNETCORE_URLS=https://*:8080
 6# Switch to root for changing dir ownership/permissions
 7USER 0
 9# Copy the binaries
10COPY /bin/release/netcoreapp1.1/publish app
12# Change to app directory
15# In order to drop the root user, we have to make some directories world
16# writable as OpenShift default security model is to run the container under
17# random UID.
18RUN chown -R 1001:0 /app && chmod -R og+rwx /app
20# Expose port 8080 for the application.
21EXPOSE 8080
23# Run container by default as user with id 1001 (default)
24USER 1001
26# Start the application using dotnet!!!
27ENTRYPOINT dotnet aspnet.on.openshift.dll

5. Create you OpenShift Cluster#

Run the following command:

1oc cluster up --host-data-dir=/mydata --version=v1.5.1

You should have a working cluster. To get the url of your cluster run:

1oc status 

Browse to your cluster (i.e and login with username: developer and password developer

6. Create an app in OpenShift#

Run the following command:

1oc new-app . --name=aspnetoc

7. Build your OpenShift image#

Run the following command

1oc start-build aspnetoc --from-dir=.

8. Create a route so you can access the application#

Run the following commands

1oc create route edge --service=aspnetoc
2oc get route aspnetoc

Copy the host/port output of the previous command (i.e.

9. Check the status and browse to you application#

Check the status with the following command

1oc status

When your pod has been deployed browse to your application using the host you copied in step 8 (i.e.

Enjoy! you just deployed your ASP.NET Core application to OpenShift.

You can get the code here.

Hope it helps!