AWS EC2 is a great service to run virtual machines in the cloud. EC2 offers hundreds of images of operating systems and pre-packaged applications to choose from when launching a virtual machine instance.
Learn how to quickly install Docker Engine and Docker Compose on AWS EC2, using any Ubuntu AMI and bootstrapping the install script.
According to Snap Store, the top 14 linux distros where Docker Engine is installed are all Ubuntu (or Ubuntu-based).
EC2 Instance with launch script (user data)
In this method I will use AWS EC2 user data feature, which allows a specific script to run during instance launch (bootstrap). I will install the docker engine from the snap store, followed by Linux post-installation steps
to be able to run docker commands such as
docker run without
- Login to AWS EC2 page and make sure you are in the correct region
Ubuntufrom the quick start page. Current default version is Ubuntu 22.04 LTS.
- Choose the instance size for your instance. t2.micro size is Free tier eligible, and is sufficient to run simple workloads in Docker.
- Create key pair and fill any other required configuration settings.
- Under Advanced details section, paste the install script in the User data box:
#!/bin/bash sudo snap install docker sudo addgroup --system docker sudo adduser ubuntu docker newgrp docker sudo snap disable docker sudo snap enable docker
Review and launch the instance.
Once your instance is up and running, wait a few minutes for the instance to initialize, then SSH to it using an SSH client like Putty .
Verify Docker is running using any of the following commands:
docker -v docker ps docker compose version docker info
Congratulations, you have built an Ubuntu VM with Docker Engine and Docker Compose running on first boot!