DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Lessons Learned Moving From On-Prem to Cloud Native
  • Keep Your Application Secrets Secret
  • Auto-Scaling a Spring Boot Native App With Nomad
  • Containerize Gradle Apps and Deploy to Kubernetes With JKube Kubernetes Gradle Plugin

Trending

  • Memory Leak Due to Time-Taking finalize() Method
  • Agentic AI for Automated Application Security and Vulnerability Management
  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Blue Skies Ahead: An AI Case Study on LLM Use for a Graph Theory Related Application
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Deploy an ASP.NET Core Application in the IBM Cloud Code Engine

Deploy an ASP.NET Core Application in the IBM Cloud Code Engine

Turn your ASP.NET application into a serverless engine.

By 
Deepak Rai user avatar
Deepak Rai
·
Jun. 06, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
10.2K Views

Join the DZone community and get the full member experience.

Join For Free

While there are many use cases to explore, in this blog we are going to explore how can you deploy a dot net core application from scratch into the IBM Cloud code engine. I would also suggest looking into this article for understanding when to use an application or a job.

What You’ll Learn in This Tutorial

Upon completion of this tutorial, you will know how to:

  • Dockerize a simple ASP.NET Core app.
  • Create your Code Engine project with an application.
  • Deploy your ASP.NET Core app to Code Engine.

Before You Begin

You’ll need the following installed on your machine.

  • IBM Cloud account
  • IBM Cloud CLI
  • Git
  • .NET Core SDK ( I have used 5.0.23)

Create and Run Dotnet Application Locally 

This step is to verify whether your app is running successfully locally before deployment. You can start by verifying the version of Dotnet as follows in your terminal:

Shell
 




x


 
1
dotnet --version



Create a sample web app using the below command. This will create a new application under the directory myWebApp and flag --no-https flag specifies not to enable HTTPS.

 

Shell
 




xxxxxxxxxx
1


 
1
dotnet new webApp -o myWebApp --no-https



In your terminal, run the following command:

Shell
 




xxxxxxxxxx
1


 
1
dotnet watch run


 

The dotnet watch run command will build and start the app, and then rebuild and restart the app whenever you make code changes. You can stop the app at any time by selecting  Ctrl+C.

Wait for the app to display that it's listening on http://localhost:5000 and for the browser to launch at that address.

Publish the ASP.NET Core App

Publish the app to get a self-contained DLL using the dotnet publish command. 

Shell
 




xxxxxxxxxx
1


 
1
dotnet publish -c Release



Running publish displays some messages with a successfully published DLL at the end of the process. 

Dockerize the ASP.NET Core App

Once the application is ready, we can make an image of it and put it inside a container. We need a file that contains step-by-step instructions to deploy the image inside the container to run our application anywhere. This Dockerfile is a basic file and you may only require a few lines to get started with your own image.

Go to the app folder (here myWebApp) and create a Dockerfile to define the Docker image.

Shell
 




xxxxxxxxxx
1


 
1
Cd myWebApp



Create a docker file:

Shell
 




xxxxxxxxxx
1


 
1
vi Dockerfile


Shell
 




xxxxxxxxxx
1


 
1
FROM mcr.microsoft.com/dotnet/aspnet:5.0
2
WORKDIR /app1
3
COPY ./bin/Release/net5.0/publish .
4
ENTRYPOINT ["dotnet", "myWebApp.dll"]
5
EXPOSE 8080
6
ENV ASPNETCORE_URLS=http://*:8080



Run the App on Docker (Optional)

You can test your dockerized app by following the steps below. This section is optional for this tutorial, though.

First, build an image.

Shell
 




xxxxxxxxxx
1


 
1
docker build -t mywebapp .



Note: You can choose any name for your app.

Running the build command displays the following message in the end.

Shell
 




xxxxxxxxxx
1


 
1
...Successfully tagged mywebapp:latest 



The following command will run an app.

Shell
 




xxxxxxxxxx
1


 
1
docker run -d -p 8080:80 --name app mywebapp



Navigate to http://localhost:8080 to access your app in a web browser.

Clean up with the following commands.

Shell
 




xxxxxxxxxx
1


 
1
docker stop /app


Shell
 




xxxxxxxxxx
1


 
1
docker rm /app



These above commands stop and remove the Docker container of your app, respectively. You can use them to remove your container if you no longer need them.

Create a Container Registry on IBM Cloud

Make sure you are logged into your IBM Cloud account by using:

 

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud login



 or 

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud login --sso


 

Log in to the Container Registry Service to store the Docker image that we created with Docker.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr login




Find your container registry namespace by running the following command.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr namespaces



If you don’t have any, create one by using the following command.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr namespace-add <name>



For Example:

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr namespace-add codeengine



Identify your Container Registry by running the following command.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr info



Build and tag (-t) the Docker image by running the command below, replacing REGISTRY and NAMESPACE with the appropriate values.

Shell
 




xxxxxxxxxx
1


 
1
docker build . -t <REGISTRY>/<NAMESPACE>/myapp:v1.0.0


 

For example:

Shell
 




xxxxxxxxxx
1


 
1
docker build . -t jp.icr.io/codeengine/myapp:v1.0.0



It will display the following message at the end.

Shell
 




xxxxxxxxxx
1


 
1
naming to jp.icr.io/codeengine/myapp:v1.0.0        



Push the Docker image to your Container Registry on IBM Cloud.

Shell
 




xxxxxxxxxx
1


 
1
docker push <REGISTRY>/<NAMESPACE>/myapp:v1.0.0



For example:

Shell
 




xxxxxxxxxx
1


 
1
docker push jp.icr.io/codeengine/myapp:v1.0.0    



Verify that the image was pushed successfully by running the following command.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr image-list


You set up a namespace in the IBM Cloud Container Registry and pushed a Docker image to your namespace.

Authorizing Access to Container Registry From The Console

Now before we jump into creating a Code Engine application, we should ensure it has all the right access to the container registry.

In order to pull or push images from or to IBM Cloud Container Registry, you must create a service ID, create an access policy for the service ID, and then create an API key to store the credentials.

Log in to IBM Cloud in the browser using https://cloud.ibm.com.

  • In the IBM Cloud console go to Manage->Access (IAM).
  • Select Service IDs.
  • select Create, enter a name and description, and click Create (name and description can be anything).
  • From the Service ID page, select Access policies and then Assign access.
  • From the Assign service ID additional access section,
  • Select IAM services.
  • Select Container Registry for the type of access.
  • You can select based on how you need access to the registry, you can select read-only access in case you need to limit access.
  • In this demo, I'll select all the access in the All resources since we are not really looking into IAM right now.
  • Click Add once you select all checkboxes.
  • Now click on Account Management under Assign service ID additional access section.
  • Select IAM Identity Service.
  • Again not going into detail about it here, will select all resources and check all boxes.
  • Click Add.
  • Click Assign next.
  • From the Service ID page, select API Keys, click create.
  • Enter name and description and click Create (name and description can be anything).
  • Copy the API key or click download to save it.

Note: You won’t be able to see this API key again, so be sure to record it in a safe place.

Now the access is taken care of, let's start creating a code engine service.

Deploy Your Containerized Application

On your IBM Cloud page, click on Catalog.

You can search for code engine, alternative you can select services -> containers -> Code Engine.

  • Select Projects.
  • Click Create, select Location. In my demo, as you have seen, I am using Tokyo.
  • Enter any name, select resource group (I have used my default resource group).
  • You can enter any tags if needed.
  •  Click Create.

Once the project is created, from the project page, click Registry access. 

  • Click Create.
  • Enter a name for your registry access.
  • Enter a server name for your registry access. For Container Registry, the server name is <region>.icr.io. For example, jp.icr.io.
  • Enter a name. For IBM Cloud Container Registry, it is iamapikey.
  • Enter the password. For IBM Cloud Container Registry, the password is your API key.
  • You can ignore the email.
  • Click Add.

From the project page, click on Applications:

  • Click create.
  • Enter name.
  • Under Choose the code to run.
  • Select Container Image.
  • Click Configure Image
  • On the Registry server, Select IBM Registry Tokyo.
  • Registry access, select the registry access name we created previously.
  • Namespace -> in our case it's codeengine, you can select the one you created.
  • Repository (image name) -> myapp.
  • Tag -> v1.0.0.
  • Click done.
  • Select create.

Conclusion

That’s all folks; if everything is done perfectly, your Dotnet application will run and you can check using the Open application URL option.

In case you face issues you can enable logging in to the dashboard and discover the issues. Click on enabling logging will show the logs if you already have a log Analysis service running, else you need to create one in the Tokyo region.

IBM Cloud ASP.NET application Cloud ASP.NET Core Docker (software) Engine app shell

Opinions expressed by DZone contributors are their own.

Related

  • Lessons Learned Moving From On-Prem to Cloud Native
  • Keep Your Application Secrets Secret
  • Auto-Scaling a Spring Boot Native App With Nomad
  • Containerize Gradle Apps and Deploy to Kubernetes With JKube Kubernetes Gradle Plugin

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!