Installing Docker On AWS LightSail Linux Ubuntu

Corey Gardner
3 min readNov 26, 2021

AWS Light Sail is basically Amazons collection of operating system images that are used to create remote virtual machines called EC2 instances. Once we deploy an EC2 instance we can connect to it via SSH. EC2 instances have a wide variety of use cases, once we’ve deployed an image we can pretty much do anything we want with it. In this example we’ll be using the Linux Ubuntu 20.04 image to create a Docker development environment.

Docker is probably the coolest thing since sliced bread. When I skimmed through DevOps For Dummies the basic explanation was that “Docker is a light weight virtual machine”. We’ll get into the differences between Docker and Virtual Machines in another post.

Why are we using Docker in the first place?

Say we have a team of remote workers who are testing and developing a Ruby on Rails app together. Everyone’s got different types of PCs all running on different software and hardware. Johnny’s laptop is running on Windows 07, Wilbur’s mac only boots in safe mode and Phil’s PC has its memory full. In other words our development team has a complete mess on their hands.

If every member of the team wanted to install Ruby On Rails7.0.0Alpha2 they’d all have to install Ruby, Rails, Node, Yarn, Bundle and a whole bunch of other stuff. No one likes installing software. And no one wants to spend hours at a time trying to install software only to find out that their native operating system and hardware actually can not handle whatever task is at hand.

By using Docker no one has to worry about jumping through hoops to install software except the guy (you) building the Docker Image. An Docker Image is a set of instructions which Docker uses to build a Container. The Image is basically a set of instructions of which software packages to install, whist the Container is the “light weight OS” that spawns and runs all of these packages.

In just a few commands every team member can be running exactly the same application within a Docker Container, and no one gets left behind because we’re using an EC2 instance for development. OK, lets get down to the dirty work!

Installing Docker on Ubuntu

First we’ll switch to root and update all of our packages by running

sudo -i && apt-update 

We’re going to install some packages to let apt use HTTPS, which in my humble opinion should be the default configuration.

apt install apt-transport-https ca-certificates curl software-properties-common

We’re going to install the GPG key for Docker, this is basically a way in which we can verify that we downloaded the actual Docker repo and don’t become the victim of a supply chain attack by.

How does GPG work? I’m glad you’re curious. Roughly speaking it is based on the OpenPGP encryption standards. Using PGP Corey can send an encrypted message to SWIM by signing ie, encrypting the message with their Private Key. Corey has posted his Public Key which everyone can use to decrypt his messages, this also verifies that the messages came from Corey. The process also works in reverse, SWIM will encode messages to Corey using his Public Key, only Corey’s Private Key will decrypt messages that are encrypted with his Public Key.

Rather than signing messages the Docker developers are signing software and providing us with their public key to validate that the package we downloaded actually came from them and was not altered.

Run this command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

You should get an OK message. If you’re reading this in the future the URL of the key may have changed so you’re going to have to look that up.

Next we’re going to add the Docker repo to our system with apt:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

apt-cache is a way in which we can search for vital information in our packages. Run apt-cache policy docker-ce . As long as the top of the output near candidate says Ubuntu-focal we’re good. Essentially we’re just making sure that we downloaded Docker from the right place.

Lets install Docker:

apt install docker-ce

Check that Docker is running systemctl status docker

Congrats you now have Docker installed !

Corey’s Corner Podcast: https://anchor.fm/coreys-corner
Gardner App Development: https://gardnerappdev.com
Get Yoked 🍳 https://thoughtsandfitness.com
Learn To Code: https://www.youtube.com/channel/UCfd8A1xfzqk7veapUhe8hLQ

--

--