How to use the Amazon Linux container image with Docker for development

Jack Wallen helps you get started with Amazon Linux as a deployable container image.

Amazon.com logo on server room wall.  Editorial 3D rendering
Image: Alexey Novikov/Adobe Stock

Did you know that Amazon Linux is available and can even be deployed outside of the AWS cloud infrastructure? That’s correct. The image is official and maintained by the Amazon Linux team.

Amazon Linux is designed to provide stable, secure, and high-performance environments for applications deployed on Amazon EC2. The distribution includes all the software you need to integrate with AWS, e.g. B. Launch configuration tools and numerous AWS libraries.

SEE: Hire Kit: Backend Developer (TechRepublic Premium)

But Amazon Linux is not limited to deployment on AWS as it is supported on any platform that Docker supports. I want to walk you through your first steps with Amazon Linux as an image that you can use for container deployment.

What you need to use Amazon Linux

The only thing you need to use Amazon Linux is a fully functional Docker environment. I will demonstrate on Ubuntu Server 22.04 and show you how to install the latest version of Docker first.

How to install Docker

First you need to add the required repository. But before that, we must first add the GPG key with the command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Next add the repository:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Before we can install Docker, let’s install some dependencies with the command:

sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y

Finally, we can install the latest version of the Docker engine:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y

Finally, add your user to the docker group with:

sudo usermod -aG docker $USER

Log out and back in for the changes to take effect.

How to pull the official Amazon Linux image

The first thing we need to do is get the official Amazon Linux image with the command:

docker pull amazonlinux

Once the image has been dragged, you can view it with:

docker images

You should see something like this:

amazonlinux   latest      3bc3c7c96b1d   3 weeks ago   164MB

How to deploy a container from the Amazon Linux image

We will now deploy the container image in such a way that we end up at the bash prompt inside the container. This is done with the command:

docker run -it amazonlinux:latest /bin/bash

How to install software on Amazon Linux

One of the first things you might want to do is update the running operating system with the command:

yum update

After the update is complete, let’s install software. We install the Nano text editor and Python with the command:

yum install nano python3 -y

How to commit your changes to the container

Once the software is installed, we apply the changes we just made to the container. First, kill the container with the command:

exit

Next, find the container ID with the following command:

docker ps -a

The ID is a random string, e.g. ffb079663b4b.

To apply the changes, the command is:

docker commit ID NAME

where ID is the container ID and NAME is a new name for the container. For example, the command could be:

docker commit ffb079663b4b amazonlinux-python

After the commit is complete, you should now see a new image with the following command:

docker images

The new image should be named amazonlinux-template and contain the added software. You can then deploy a new container from that image with a command like this:

docker run -it amazonlinux-python /bin/bash

You will then find yourself in a new container based on the Amazon Linux image you created, containing both the Nano text editor and the Python programming language. You can now start developing Python apps in this containerized environment.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for the latest tech advice for business professionals from Jack Wallen.

Leave a Reply

Your email address will not be published. Required fields are marked *