GUIDE

Install Docker on AWS Linux 2023

Deploy Docker on AWS Linux

How do I install docker and docker-compose on an AWS EC2 or Lightsail AWS Linux instance?   This guide will walk you through step by step to quickly build, test and deploy Docker on AWS.

A little Docker history:  Docker floated onto the scene in 2013 and within a month of its first test release, it became the playground for ~10,000 users. By the time Docker 1.0 was released in 2014, the software had been downloaded 2.75 million times, and within a year after that, more than 100 million.   Docker usage has continued to increase since its release and has a large marketshare across the globe.

Requirements

  1. EC2 or Lightsail instance running AWS Linux

Connect & Update your AWS instance

(I will be using an EC2 t2.small AWS Linux 2023 instance)

 Connect to your AWS Linux instance and run the following commands to update the OS to the latest version

sudo yum update && sudo yum upgrade -y

Update AWS Linux using YUM

Verify Docker SE

Before we install Docker SE we need to verify it is available via yum and is the correct version before install.

 

Search for Docker:  sudo yum search docker
Get Version Information:  sudo yum info docker

Using these commands we have determined Docker is available via yum and is at the latest version  20.10.25 and ready to be installed.

verify docker version

Install Docker SE

Install Docker with the following command:  

 sudo yum install docker -y

Install Docker SE on AWS

Enable the ec2-user to run Docker without using the sudo command.

 

Add ec2-user to the “docker” group using the following command:

sudo usermod -a -G docker ec2-user

Verify ec2-user belongs to the “docker” group:

id ec2-user

Reload “docker” group assignment w/o logout

newgrp docker

Run a docker container without sudo

 

Install Docker-Compose

Installing docker-compose is completely optional but I highly recommended.  

In a nut-shell Docker Compose is assists in defining and sharing multi-container applications (aka stacks). By using Compose, we can define the services in a YAML file,  spin them up, and tear them down with one single command.  Want to know more?  Check out the Official Docker Compose Documentation.

 

There are a couple ways to install docker-compose, my preference is pulling it directly from github.

 

Download docker-compose from Docker’s github:

wget https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) 

 

Move docker-compose to /usr/local/bin and apply user permissions:

sudo mv docker-compose-$(uname -s)-$(uname -m) /usr/local/bin/docker-compose

 

Change docker-compose file permission to allow it to be executed:

sudo chmod -v +x /usr/local/bin/docker-compose

install docker compose on AWS linux

Verify your Docker & Docker-Compose

 

Run this command to get the Docker service status:

sudo systemctl status docker.service

Check the docker version

docker version

Check the docker-compose version

docker-compose version 

Verify version of docker and docker-compose

Enable and Start docker service at boot time

 

Enable Docker service at AMI boot time:

sudo systemctl enable docker.service

Start the Docker service:

sudo systemctl start docker.service

enable docker service

Final Test:  Run “Hello-World”

  

Now that we have a fully configured a AWS Linux instance with Docker, the final test is to run the “Hello-World” container.   Running this simple container will pull down the “Hello-World” image from hub.docker.com, run the image, and output some simple text.   If there aren’t any errors then we have successfully completed the install and the server is ready for use.

 

Run the Hello-World docker image:

docker run hello-world  

run hello-world docker image

 

Appendix

How to control your docker service

Start the docker service:

sudo systemctl start docker.service

Stop the docker service:

sudo systemctl stop docker.service

Restart the docker service:

sudo systemctl restart docker.service

Status of the docker service:

sudo systemctl status docker.service

What to Learn More?

This is one of my favorite books on Docker!  This book walks you through get into building, testing, deploying, and debugging Linux containers with Docker.   Going beyond manual administration by touching on some cool orchestration tools that make the most out of Linux containers.  One thing that separates this book from others is that it focuses on security and best practices for your container setup which was invaluable to me as I started my Docker journey.