How to Use Amazon Linux Container Image with Docker for Development

0

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

Image: Alexei Novikov/Adobe Stock

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

Amazon Linux was designed for use in stable, secure, and high-performance environments for applications deployed on Amazon EC2. The distribution includes all the software you need for integration with AWS, such as launch configuration tools and many AWS libraries.

SEE: Recruitment kit: Back-end developer (TechRepublic Premium)

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

What you’ll need to use Amazon Linux

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

How to install Docker

The first thing to do is to add the necessary repository. Before that, however, we first need to 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 log back in for the changes to take effect.

How to Extract the Official Amazon Linux Image

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

docker pull amazonlinux

Once the image is extracted, 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 so that we end up in the container at the bash prompt. This is accomplished with the command:

docker run -it amazonlinux:latest /bin/bash

How to Install Software on Amazon Linux

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

yum update

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

yum install nano python3 -y

How to commit your changes to the container

Once the software is installed, we will commit the changes we just made to the container. First, exit the container with the command:

exit

Then locate the container ID using the command:

docker ps -a

The ID will be a random string, such as ffb079663b4b.

To validate the modifications, the command will be:

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

Once the commit is complete, you should now see a new image listed with the command:

docker images

The new image should be named amazonlinux-template and will include 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, which contains both the nano text editor and the Python programming language. You are now ready to start developing Python applications in this containerized environment.

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

Share.

Comments are closed.