Question

Best Practices to Deploy Docker on DigitalOcean using Terraform

Hi guys … I’m wondering if there are some best practices to deploy Docker images to Digital Ocean using Terraform.

Because I don’t expect much load and don’t need failover features etc. I’m not aiming to deploy to kubernetes. At least not for the moment. I just wanna deploy a standalone Docker app.

This leads me to the question whether there are some best practices on how to deploy Docker images via Terraform. To it seemls like I can use (1) App platform or (2) provision a droplet with docker and run the image inside the droplet myself.

I’d prefer to deploy to the App platform. But I don’t have a handle on how I can use public images from DockerHub. The App platform itself (via WebIU) supports this. But from the Terraform docs I cannot get a handle on this.

As far as I see it, the app platform is simpler and more straight forward for Docker images. Plus I don’t have to setup that many domain-information (I wanna point my existing docs.sommerfeld.io to the App). Downside is that I have to setup a CNAME entry with my Domain Hoster to a <random>.digitalocean.app URL which maybe I cannot do automatically. Plus as said I don’t know how to use a public image from DockerHub.

Using the droplet means I would have to do more stuff on my own

  • Provisioning the droplet as well as making sure all needed software is installed and my docker image is started
  • More domain and CNAME configs on my own
  • Setting up https with certs (from let’s enctypt) on my own.

So to summarize, here are my questions:

  1. Do I understand everything I described correctly? Or am I mistaken somewhere?
  2. Are there some best practices I should follow? How would you tackle my issue? I don’t really have a starting point so a push in the right direction would really help me out.

Thanks guys and best regards. Sebastian


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

Indeed all of the things that you’ve pointed out are correct!

I would have a couple of remarks:

  • Adding DNS records: you would need to do that in either cases, so no matter if you go with the App Platform or a Droplet + Terraform, you would still need to add a DNS entry to point your domain to your Droplet’s IP or your App Platform.
  • Once you deploy to the App Platform, you would need to add the DNS record once, then if you deploy new versions of your app, the CNAME record would not change.
  • You can deploy a Docker image from Docker hub by following the steps here:

https://docs.digitalocean.com/products/app-platform/how-to/deploy-from-container-images/

Then once deployed, future updates will be automatic. So when updating the source image tag, a new deployment will be triggered.

  • You don’t necessarily need Terraform if you go with the App Platform, but in case that you prefer to use it, you can do so and even specify Docker images as described in the docs here:

https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/app

And one last thing, if you change your Nameservers to the DigitalOcean ones, you will be actually able to automate the DNS records creation by using Terraform as well or the DigitalOcean API:

https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/data-sources/domain

Hope that this helps!

Best,

Bobby