Using custom domains with Triton Container Name Service

April 04, 2017 - by Alexandra White

Watch this video to learn more about how to assign your custom domain name to any instance on Triton.

Read on below to learn more, or watch the introduction to CNS and using CNS with Docker videos. The full transcript of this video is available below.

Make your application fun with custom domains

New top-level domain extensions like .codes, .rocks, .llp, and .wtf make it fun to find the perfect name for your application or website. Triton CNS is the perfect way to add a custom domain to your application, allowing you to scale up and down quickly without having to do any extra work. Together, they're a match made in web heaven.

Your Triton instance can have any domain name associated with it, with no extension restrictions. There are several providers who sell domain names including Namecheap (my registrar of choice), Hover, Name.com, and too many more to list, where you can find the right fit.

Being fond of space, I purchased "alexandra.space" and waited for an opportunity to put it to good use. There's no better time than the present!

The exact process of assigning a vanity domain looks different depending on your registrar. I use Namecheap to manage alexandra.space.

My dashboard assigning DNS names to CNAMEs

I built a WordPress website and added Triton CNS. It's important that visitors be directed to the frontend of my application, and not to one of the other services which are included in the Autopilot Pattern implementation of WordPress. Nginx is the service used as an HTTP server to serve content, so my CNAME points to the CNS-generated DNS name for the Nginx containers. When I scale or update the Nginx containers, the IP numbers may change (new container = new IP), but the generated CNS name for the Nginx service remains the same. The new IPs will be reflected in the DNS without having to lift a finger.

I manually set the CNAME for my custom domain once. Triton CNS took care of everything else from there.

No matter how many times I rebuild or update WordPress, you will still be able to open alexandra.space in your browser and interact with the website.

The Autopilot Pattern WordPress implementation has the tags and labels to use Triton CNS baked-in, but you can easily add it to any application. Watch a video to learn how to use Triton CNS with Docker.

Video transcript

Welcome to this tutorial for assigning vanity domains to Triton instances with Triton Container Name Service.

You can learn about the awesome DNS power of Triton CNS in our introduction video.

With Triton CNS, you’ll automatically be assigned a DNS name starting with your CNS service name, and including your account UUID and data center name. Get in-depth details on how to add Triton CNS to your instances by reading our Triton CNS with Docker blog post or by watching the corresponding video. In order to add a vanity name to an instance, you have to know its current DNS name. List all of your instances to find your application, and get its DNS name with triton instance get.

Triton will tell you a lot of information about your instance. The last section of details contains the DNS names, including your CNS-powered domain name.

You can visit my Nginx application with that DNS name and do no additional work. No matter how many times you scale your application or share it, that DNS name will remain the same.

However, that DNS name is awfully long and complicated to try and remember. It will be far easier to direct visitors to a meaningful vanity domain instead.

The best way to assign your Triton CNS powered application to a vanity domain is to use canonical name records, or a CNAME. CNAMEs are used to specify that a domain name is an alias for another domain.

The Triton-assigned DNS name is the CNAME and the vanity domain is its alias.

Why do we use CNAMEs instead of IP addresses? If you scale up a service with Triton CNS, each instance will have different IP addresses, but will share that same DNS name. You won’t have to do extra work every time you scale up or down.

On my domain registrar, I have own several domains which I could use for my application. This process may look different for different domain registrars, but the concepts remain the same.

I’ll assign my CNAME to hello.alexandra.space.

The CNAME may take some time to propagate. You can check in on your vanity domain by using dig.

DIG, which stands for Domain Information Groper, is a command-line tool for looking up DNS name servers. If you head to your vanity domain and wonder “why is my website not here?”, your first course of action should always be to dig.

In the answers section, you can see that my domain name is assigned to my CNAME, the Triton assigned DNS name. The record has a remaining time to live of 1799 seconds, which means that it will take up to that many seconds to reflect any changes made to the DNS record.

Beneath the CNAME is an A Record, which stores the IP address associated with your instance. If you scaled up and the Triton CNS name is assigned to multiple instances, those instance IP addresses would all show up, beneath the CNAME.

Now that I know my vanity domain is properly directed, I can visit hello.alexandra.space in the browser.

If I decide that one instance isn’t enough, I can scale up my application quickly. By dig-ing hello.alexandra.space again, I can see that there are now multiple IP addresses pointing to my vanity domain.

That’s the CNS magic, automatically referencing the multiple instances tagged with a CNS service name.

And when I don’t need as much power backing up my application, I can scale back down, which will remove those extra IP addresses from pointing to my domain name. I don’t have to do any extra work to map the DNS names, it’s all done automatically.

If I decided to delete all of my existing application instances, my website would point to nothing... but when I spin up my application again, no matter the IP address of the new instances, it still just works.

You're now ready to assign a vanity domain to any application on Triton.

Learn more about how Triton's networking capabilities will make your applications faster and easier to scale.