top of page

How to run apps inside AWS Lightsail using Docker

3 hours ago
5 min read

AWS LightSail is a service provided by AWS (Amazon Web Services) that provides the deployment and management of Virtual Private Servers (VPS), databases, as well as storage in a very straightforward way, being recommended for small businesses, developer projects and for cloud beginners, with most of the main settings being pre-configured during the creation of the instance. 


In this article, I’ll cover how to create an instance and deploy an app within your LightSail instance. 

 

Step 1: Access AWS LightSail from your Management Console 


Once you have created your AWS Account, access the AWS Management Console by selecting My account and clicking AWS Management Console. 


Go to the AWS page and click on My Account to find the AWS Management Console (Screenshot: AWS) 
Go to the AWS page and click on My Account to find the AWS Management Console (Screenshot: AWS) 

 

Then, you are going to click on the button All Services 

 

Inside the Management Console, click on All serviçes on the top right corner of Recently visited to see the list of services provided by AWS (Screenshot: AWS Console) 
Inside the Management Console, click on All serviçes on the top right corner of Recently visited to see the list of services provided by AWS (Screenshot: AWS Console) 

And select the Lightsail option

Inside the list of AWS services, select the option Lightsail (Screenshot: AWS Console) 
Inside the list of AWS services, select the option Lightsail (Screenshot: AWS Console) 

Step 2: Set up your instance 

Once you’re inside Amazon Lightsail, go to Instances and select the button Create Instance  

Inside Lightsail, select the Create Instance button inside the Instances tab to create your instance (Screenshot: AWS Lightsail) 
Inside Lightsail, select the Create Instance button inside the Instances tab to create your instance (Screenshot: AWS Lightsail) 

 

Inside Create an instance, you will select the closest server option to your location in Instance location: 

Select the nearest option to you in Instance Location (Screenshot: AWS Lightsail) 
Select the nearest option to you in Instance Location (Screenshot: AWS Lightsail) 

 

Then, you are going to select the Linux operating system in Select a platform and select Ubuntu 24.04 in Select a blueprint, as we are going to create an instance to deploy an App 


Select Linux operating System and Ubuntu 24.04 in the Pick your instance image section on the Create Instance page (Screenshot: AWS Lightsail)
Select Linux operating System and Ubuntu 24.04 in the Pick your instance image section on the Create Instance page (Screenshot: AWS Lightsail)

 

After selecting the blueprint, let the option General Propose in Select a plan type  and select the option Dual-stack for the Select a network type setting. 


Select General Purpose and Dual-Stack in the Choose your instance plan section (Screenshot: AWS Lightsail) 
Select General Purpose and Dual-Stack in the Choose your instance plan section (Screenshot: AWS Lightsail) 

 

Then, you will select one of the options in Select Size. In this scenario, to save money but maintain good performance, we will use the $24 option:


Select an option in the Select Size section (Screenshot: AWS Lightsail) 
Select an option in the Select Size section (Screenshot: AWS Lightsail) 

Then, write your Instance name just below the Size options and configure the Automatic snapshot, in case you wish to do automatic snapshots.


Write your instance name and set the Automatic Snapshots if you want to enable automatic snapshots in Configure your instance (Screenshot: AWS Lightsail)
Write your instance name and set the Automatic Snapshots if you want to enable automatic snapshots in Configure your instance (Screenshot: AWS Lightsail)

 

Keynote: Although we chose the Linux operating system and the Ubuntu 24.04 blueprint, you can choose other settings for the instance; however, costs may be different according to the options you choose. 


Step 3: Connect your instance with an SSH Key to your machine (optional) 

Once your instance is created, you will connect to it from your machine or browser to deploy the application that you wish to run inside AWS. If your goal is to connect with your machine instead of using the browser you are accessing LightSail, you need to create an SSH Key to proceed with the next steps. 

Having the SSH Key in hand, you will open Advanced settings and select the Upload Key button: 


Click on the Upload Key to use your SSH Key inside Lightsail (Screenshot: AWS Lightsail)
Click on the Upload Key to use your SSH Key inside Lightsail (Screenshot: AWS Lightsail)

 

After selecting it, click Upload in the pop-up, click the Choose file button, select your public SSH key, and upload it to AWS Lightsail: 


Inside the pop-up, click Choose file and upload your key, then select the Upload key button to finish the upload (Screenshot: AWS Lightsail)
Inside the pop-up, click Choose file and upload your key, then select the Upload key button to finish the upload (Screenshot: AWS Lightsail)

Once your SSH Key is shown in the instance, select Create Instance: 


Once your SSH Key name is shown in the SSH Key list, you are ready to create the instance with the SSH key linked to it (Screenshot: AWS Lightsail) 
Once your SSH Key name is shown in the SSH Key list, you are ready to create the instance with the SSH key linked to it (Screenshot: AWS Lightsail) 

 

After creating the instance, to connect with the terminal of your machine, you will type the following command: 

ssh –i your-key-name username@instance_public_ip 

 

The private key used in your-key-name must contain the path for your SSH Key, unless you are using the terminal in the same folder as the key. On the other hand, the username and the instance public IP are in the Connect section inside the instance, so you must copy and use them for the command 

Just below the instance details card, by selecting the option Connect, you will find the Public IP and Username of your instance (Screenshot: AWS Lightsail)
Just below the instance details card, by selecting the option Connect, you will find the Public IP and Username of your instance (Screenshot: AWS Lightsail)

 

Once you have retrieved all the information required, you’ll be able to connect the instance to your machine’s terminal: 


Screenshot: Windows Command Prompt
Screenshot: Windows Command Prompt

 

Step 4: Deploying an application using Docker 

Lastly, now that the instance is built in Lightsail, you will deploy your app. To achieve it, you’ll connect your browser or local Machine to your instance and deploy the project you want to run.  

In this case, I’m going to use the crccheck/hello-world from Docker Hub to demonstrate how you run your app. After I installed Docker on Ubuntu using the prompt, I logged in to Docker and used the following command to retrieve and run the application as a container: 

 

docker run -d --rm --name web-test -p 8000:80 crccheck/hello-world 

 

And after running the command, this was the result: 

Screenshot: Windows Command Prompt
Screenshot: Windows Command Prompt

 

In the HTTP address provided by the container: 

Screenshot: Application running in Webpage
Screenshot: Application running in Webpage

 

Note: In case the command above returns the message "permission denied while trying to connect to the docker API at unix:///var/run/docker.sock ", use the following command before trying to execute the command again: 

 sudo usermod -aG docker $USER && newgrp docker 

Final Considerations 


It's worth mentioning that besides the settings of the instance created and the Docker Hub image used here, you can use other options such as GitHub to store your project with the Dockerfile that will generate the Docker Container of your app. Also, the same happens in AWS Lightsail, with Lightsail providing different settings for different kinds of projects, so if you want to deploy your Node.js Project, it contains a proper blueprint for Node.JS to reduce the need for manually setting up the instance for this library. 

Finally, it's worth mentioning that Lightsail offers a more reliable and easy-to-run path than EC2, but it also has some trade-offs, especially related to flexibility. So, if your project requires more flexibility in matters such as security or even high-performance computing, and you are up to accept a more dynamic price instead of a fixed one, EC2 may be the best option for you. 


About the author: Felipe Elijah is a Salesforce and Full Stack Engineer at BRF Consulting.


BRF Consulting is an Amazon AWS registered partner specializing in Cloud Computing, Salesforce, Artificial Intelligence, Data Engineering, and Software Development, assisting businesses to scale and become more efficient. For more information about our services, email us at contact@brfconsulting.com.


Comments


bottom of page