This is the fourth post in a series on deploying a very simple ASP.NET Core application different cloud provides. This post is going to be dealing with setup and deployment to DigitalOcean.
Google Cloud Platform
Amazon Web Services
Microsoft Azure
DigitalOcean (this post)
Sample Application
The sample application ended up becoming its own blog post since it looks like the easiest deployment to DigitalOcean for .NET is going to be using Docker. Check out my Adding Docker to an ASP.NET Core Application post to get your application setup with Docker and published to a registry.
DigitalOcean
Head over to DigitalOcean and sign up for an account. Using that link will get you $10 in free credit (I will get some credit too if you spend $25 or more, but the main point is to get you some credit to get started with).
As part of the sign-up process, you will have to enter a credit card. It won’t be charged as long as you don’t go over your free credit.
After you finish the sign-up process you will be dropped on the dashboard for your account. Click the Create Droplet button to get started.
On the next page select One-click apps, and then the Docker option.
Scroll down and select your Droplet size. Since this is a basic example and will never have any real traffic I went with the cheapest option which is $5 a month.
There are a lot of options, but with the two selections above we can take the defaults are the rest of them for this sample. Scroll all the way down and click the Create button.
This will drop you back to your Dashboard and you will have your new Droplet listed. Click on the name of the Droplet to get to its details.
There is a lot of information on this page, but the thing we are interested in is the Console link in the top right of the summary.
A new browser window should open with a console that is running on your Droplet.
If you are like me and took the defaults when creating your Droplet then you will have gotten an email from DigitalOcean with the username and password you can use to log in. You will be forced to change your password on your first log in.
Installing the sample application
Now that our Droplet is up and we are logged in it is time to get our application up and running. All of this section is going to be happening in the console of the Droplet. First, use the following command to log in with Docker.
docker login
Next, we need to pull the image for our application (your image name will be different).
docker pull elanderson/testrepository
The following command can then be used to run the application. -p 80:80
in the command is binding port 80 from the container to port 80 on the host. Hopefully, if you took the defaults on everything this will just work for you, but if not you will tweak this part of the command.
docker run -p 80:80 elanderson/testrepository
Wrapping Up
There were some details to work out, but after getting over those humps Docker is amazing. This post was about DigitalOcean, but I could take the image used in this post and deploy it to any Linux image that supports ASP.NET Core and Docker. Hopefully, I will find an excuse to play around more with Docker soon.
Also published on Medium.
thank you very much for this post. This is EXACTLY what I am looking for!
only 1 error after I run
docker run -p 443:443 myname/myimage:init
docker: Error response from daemon: driver failed programming external connectivity on endpoint flamboyant_germain (b8xxxx) Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use.
Please help!
I figured it out, the port has been occupied by others, so I simply used another port.
Cheer!!!!
I finally made the command below without exception:
“docker run -p 80:80 jn1921/jn”
But now. How I am supposed to open the web app.
I tried with the public ip adress of my droplet but it’s not working.
Any help would be appreciate.
Sorry mathieu it has been too long since I wrote this post. I don’t recall the address. Did you try your droplet address with port 80?
Pingback: How can I access the root of my asp.net web server? – Docker Questions