It’s a combination of two logos. Don’t think about it too hard.

Creating a simple website with a custom domain on Amazon Lightsail + Docker

Joshua Miller
10 min readDec 12, 2017

--

A developer’s guide on creating a super simple website that has a custom domain name with Docker and Amazon Lightsail.

Article Organization

  • Who is this article really for?
  • How to read this article.
  • What will be made?
  • The actual walkthrough
  • A brief explanation on “Why Amazon Lightsail and Docker?”

Who is this article really for?

The term “developer’s guide” in the subtitle could refer to the fact that the author (me) is technically a developer, or it could refer to my assumption that developers may find this article to be more useful than those who do not care about development. So, which is it? My answer is, “it doesn’t really matter.” This article should be written in such a way that all of the steps are easily reproducible, regardless of skill level. If you have some free time and you love learning, read on regardless of your field!

How to read this article

Throughout this article are steps that are probably best understood through visuals, so GIFs have been included (mostly) directly below headings. How you read this is up to you, but I suggest first reading the headings, then taking note of the GIFs, and then reading the actual steps. If you get stuck on a step, refer back to the GIF.

What will be made?

It’s not the prettiest, but that’s not the point.

The Actual Walkthrough

Having the following items prepared will allow you to move quicker through this article.

  • An account with Amazon Web Services.
  • A custom domain (I’ll be using Namecheap for the last few steps, but the steps themselves should be easily replicated with other registrars). If there is enough interest in other registrars, I may provide additional tutorials.

Quick aside: There are many options for getting a custom domain name (Namecheap, GoDaddy, Google Domains, etc). Some sites, like Freenom or .tech (for students), even offer free domain registrations. Unfortunately, I was having trouble with Freenom and I’m not a “.edu” student anymore, so I ended up buying a domain for this article (it was only $0.48 for the first year, thankfully).

Step 1 — Create an Amazon Lightsail instance

  1. On the main Lightsail Instances page, click Create Instance.
  2. Select Linux/Unix as your platform
  3. Select OS Only as the blueprint filter
  4. Select Ubuntu as the blueprint
  5. Select whatever plan you want (notice that you can try out a plan for free for one month for up to 750 hours)
  6. Name your instance (I like to append its purpose at the end, such as the _app in my instance’s name)
  7. Click Create
  8. Woo! You just created a Lightsail instance.

Hopefully the gif loaded before all of those steps… Seeing it happen is a lot nicer than reading about it, in my opinion.

Important! Please note that it will cost $5 a month to host on Lightsail after the free trial ends (this is still one of the cheapest long-term offers I’ve ever seen).

Step 2 — Install Docker

The version of Docker is highlighted at the end of this GIF.

A discussion about Docker is outside the scope of this article, so if you don’t know what it is, look it up! Knowledge around Docker, and containers in general, is a pretty nice addition to anyone’s toolbox.

At this point, we’re going to be typing some things (or copy pasting, if we’re being completely honest) via Lightsail’s built in terminal. Don’t be scared though! You don’t have to recognize or know all of the commands we will be using (you would probably feel more comfortable if you did though, so again, look up whatever you don’t recognize). Docker itself has an article on how to install the client on Ubuntu that goes into more depth on the separate commands.

To access your Lightsail instance’s terminal, click the button to the left of your instance’s menu icon (please refer to the picture shown below this sentence).

The terminal button is in the dotted red box.

For convenience, I’ve formatted all of the commands in such a way that you only need to copy paste one “thing” into the terminal. I highly recommend understanding what is going on with these steps before trying to use it in a production setting (check out the linked article 2 paragraphs prior to this one). So, without further ado, copy paste lines 1 through 14 from below into the terminal.

https://gist.github.com/JoshuaTheMiller/c8203dfd4c9b423401d52692222b499b

Pasting in the terminal is slightly odd… To successfully paste into the terminal, follow the steps presented below:

  1. Copy whatever it is that you wish to paste.
  2. In the lower right hand corner of the terminal, click the clipboard icon.
  3. Paste what you copied into the space that is presented.
  4. Click back into the terminal.
  5. Right click on the terminal to paste into it.
  6. Hit enter to execute your pasted command.

Step 3 — Setup a container

Now that we have Docker installed, it’s time to add a running container. If you have your own image of a web app and you know how to add it, use yours and skip to the next step. To keep things simple, I’m just going to use an image I created for this article.

In the terminal of your Lightsail instance, type/paste line 1 from below:

https://gist.github.com/JoshuaTheMiller/8d3ef20a26b46eb92a7482ecb1624a3f

This run command does a few things (the options are explained in reverse for some reason):

  1. It tells Docker we’re going to try and create a container using my SimpleWeb docker image (trfc/simpleweb).
  2. The --rm option signals that this container should be removed when it exits/stops.
  3. -d, which is short for the--detach, causes this container to be ran in the background. It also causes the container’s ID to be printed to the console when the command is ran.
  4. -p, which is short for --publish, publishes a container's port(s) to the host (I’ve seen this be referred to as being short for --ports,which is incorrect but makes some sense). Here, we are binding our host’s (the VM’s) port 80 to the container’s port 80 as that is the default port for HTTP traffic.
  5. The--name option is passed and set to simple so that the container’s “names” field is set to “simple.”

To verify that your new container is running, type/paste sudo docker ps. You should see a line item for a container with a “Names” of simple.

If you don’t see it, drop me a comment or contact me directly. I’ll try to find the time to help!

To stop running the container, type/paste sudo docker stop simple. This tells Docker to stop running a container named “simple” (which was the name we gave it when it was created). Remember, because the --rm option was set, stopping the container also removes it.

Step 4 — Quick Test

If you exposed your container on port 80 (if you used the commands in step 3, you did) then simply navigating to your Lightsail instance’s current ip address should display your website! Follow the next few steps to find the current ip address of your instance:

  1. Go back to the Lightsail dashboard.
  2. Notice that there is an address listed below the terminal button from before.
  3. Follow that address.

OR

  1. Go back to the Lightsail dashboard.
  2. Click on the instance you created.
  3. Find the Public IP.
  4. Copy the address displayed underneath and paste it into your browser. You should be taken to a page that looks like the image from the earlier section “What will be made?” (disclaimer: I’m not worried about exposing the various addresses that are shown as my demo instance is very temporal).

Step 5 — Setting up your static IP address

Why would you want to do this? Amazon puts it nicely:

A Static IP is a fixed, public IP address that you can always rely on to be the same. ~ Amazon

Basically, the address you followed in Step 4 can change as it is dynamic. Imagine sharing that dynamic address with your friends, family, and coworkers, only for it to stop working at some random point. How frustrating.

To setup a Static IP, follow the steps listed below.

  1. Go back to the Lightsail dashboard.
  2. Click Networking.
  3. Click Create a static IP.
  4. Attach it to the Lightsail instance you created.
  5. Name it something, I called mine supersimplesite_staticip.
  6. Click Create.

If you look at your instance’s public IP, you’ll notice that it is now set to the static IP address you just created.

Step 6— Setting up your custom domain

If you’re happy with your random, static, IP address, then you’re done! If you’d like an address that is a little easier to remember, or if you’re just curious as to what spelling mistakes I may still make, then read on.

I’ll be using Namecheap for this part, but the steps should be similar for whatever registrar you use. Additionally, please have a domain already purchased.

This part now requires some coordination between Lightsail and Namecheap, so please log in to both services so as to have them handy.

From your Lightsail dashboard, perform the following steps:

  1. Click Networking.
  2. Click Create DNS zone.
  3. Enter the domain you have registered/own in the box titled, “Enter the domain you have registered.”
  4. Click Create DNS Zone.
  5. Under DNS records, add an A record (you can add more later). For this initial record, just write in your bare domain (no www). For the Destination IP, Lightsail is nice and presents you with autofill options. Make sure to choose the static IP resource that you just created.
  6. Click Save to save your DNS Records changes.
  7. Do not close this page as we will be copy/pasting the Nameserver addresses that are listed at the bottom of it.

Now, navigate over to your Namecheap dashboard and perform the following steps:

  1. Click “Manage” for the site that you are using for this tutorial.
  2. Find the row labelled Nameservers and change the selection from Namecheap BasicDNS to Custom DNS.
  3. Add two more nameserver rows by clicking Add Nameserver.
  4. One by one, copy and paste the nameservers from your Lightsail page on the nameserver rows in Namecheap. Make sure to copy all of the nameservers listed on Lightsail.
  5. Click the little green check-mark to signify that you are done.

Notice: you may not be able to connect immediately to your website using your custom domain, as it can take up to 48 hours for the nameserver change to go into effect.

Step 7 — Wait and Verify

At this point, within 48 hours, and if all of the steps were followed correctly, navigating to your custom domain should take you to a page that states, “If you can see this, it worked!”

Congratulations!

Why Amazon Lightsail and Docker?

First off, why Lightsail? Again, Amazon puts it best:

Lightsail provides developers compute, storage, and networking capacity and capabilities to deploy and manage websites and web applications in the cloud. Lightsail includes everything you need to launch your project quickly — a virtual machine, SSD-based storage, data transfer, DNS management, and a static IP — for a low, predictable monthly price.

In other words, it had the features I wanted at a super cheap price! True, there are other options out in the wilds of the internet that offer more services, but they are also more expensive. All I want to run is a small hobby site, all of those extra bells and whistles are somewhat unnecessary. Additionally, I like learning about technologies I may not be familiar with (I’ve used Microsoft Azure, not AWS, for the past 1.25 years).

The reason I chose Docker is simple: it allows me to easily replicate my production setup anywhere and at any time that I want to. This is important because it allows me to quickly see how my applications will look/work in a production setting. Secondly, it allows me to debug issues without impacting my actual production version. Lastly (this is honestly my biggest reason), I can easily move my applications between web platforms when I have them containerized (e.g. from Heroku to Azure to AWS, or in some other order).

Ending Statements

I hope this article helped others as much as writing it helped me! Amazon Lightsail seems, so far, to be a great service at an astoundingly affordable price. If you would like an article that goes into more depth per step, or if you have suggestions on any other writing topics, drop a comment below!

If you’re curious about other web platforms, check out offerings from Microsoft Azure, Heroku, Digital Ocean, and, of course, Amazon Web Services (to name a few)!

--

--

Joshua Miller

Just a guy trying to share some knowledge about various topics that he finds interesting.