How to run apps inside AWS Lightsail using Docker
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.

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

And select the Lightsail option

Step 2: Set up your instance
Once you’re inside Amazon Lightsail, go to Instances and select the button Create Instance

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

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

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.

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:

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

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:

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:

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

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

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

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:

In the HTTP address provided by the container:

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