Deploying a Docker on Digital Ocean Droplet
In this tutorial, I will walk you through deploying your Docker container to a Digital Ocean droplet. All commands will be manually run. You can automate this process if you would like but the purpose is for getting you up and running. My Docker container will be running a Springboot app on port 8080. I expect you to have some sort of Docker container with a basic web page (API, hello world, full web app, anything at the root).
We will need to release our Docker image to a centralized hub. This is where the droplet will eventually pull it from. I'm going to use Docker.com. They offer one free repository. There are other options like Amazon ECR, Github Repository, you can setup AWS S3 or Digital Ocean Spaces, etc. The overall goal is to get the Docker container onto the droplet.
Create your repository. Once you are all setup on the Docker.com page. You will need to create your
Dockerfile in your actual project. My
Dockerfile looks like this:
This runs my Springboot app and exposes port 8080. I can build it with the following command:
This should run your Docker container locally. For doing a proper Docker release you need to sign into your account and issue the release command.
Your container should now be released. You can look it up on your Docker repository.
Deploying your Droplet
Now it's time to deploy your Droplet. You can do this via the console, the API, or tools like Terraform. Start by signing in to your Digital Ocean account.
Or you can do this via API with curl:
This will create your new Droplet. Either you will have setup SSH keys or you will be emailed credentials.
Sub in real values for all throughout script.
Open your IP address in your web browser. You should see your page.
Adding a Domain
The next steps will be adding a domain. You will need to sign in to your account that manages your domains (Ex. GoDaddy) and find the DNS for that domain. You will want to create a type a record that has a host value of @ and it will point to your server ip.
Once, your domain updates - you should see the same message as the IP address in your web browser.
On your server, you'll have to configure it to expect this domain. You will have to
ssh back into the server.
Update your domain where
Your domain should all be setup on a
Side note: GoDaddy has an API and if you are automating this deployment process, try it out. The curl call looks like this:
Sub in your GoDaddy API key, your domain and your IP address.
Adding an SSL
The last step is setting up your server to accept traffic over
HTTPS. Handling traffic over a secured traffic is highly recommended and really should be mandatory. You will not be able to do this if you do not have a domain.
The first step is to
ssh into your server.
Sub in your domain where
your_domain.ca and your email where
If this is successful, it will say congratulations. For those who are adding pipelines or automated deployments, you can only run this 5 times a week.
You should have a fully setup Digital Ocean droplet. You will have access to this lesson for as long as it exists.