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


Jack Wallen helps you take your first steps with Amazon Linux as a deployable container image.

Image: Alexey Novikov/Adobe Stock

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

Amazon Linux has been designed to be used for stable, secure, and high-performance environments for applications that are deployed on Amazon EC2. The distribution includes all the software you need to integrate with AWS, such as launch config tools and plenty of AWS libraries.

SEE: Hiring kit: Back-end Developer (TechRepublic Premium)

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

What you’ll need to use Amazon Linux

The only thing you’ll need to use Amazon Linux is a fully-functioning Docker environment. I’ll be demonstrating on Ubuntu Server 22.04 and will show you how to first get the latest version of Docker installed.

How to install Docker

The first thing to do is add the necessary repository. Before that, however, 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 a few 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

To finish things up, add your user to the docker group with:

sudo usermod -aG docker $USER

Log out and log back in so the changes will take effect.

How to pull the official Amazon Linux image

The first thing we must do is pull the official Amazon Linux image with the command:

docker pull amazonlinux

Once the image has been pulled, 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’re now going to deploy the container image in such a way that we’ll wind up within 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 you might want to do is update the running OS with the command:

yum update

Once the update completes, let’s install some software. We’ll 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’ll commit the changes we just made to the container. First, exit the container with the command:

exit

Next, locate the container ID with the command:

docker ps -a

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

To commit the changes, the command will be:

docker commit ID NAME

Where ID is the container ID and NAME is a new name for the container. For instance, the command might be:

docker commit ffb079663b4b amazonlinux-python

After the commit completes, 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’ll then find yourself within a new container, based on the Amazon Linux image you created that contains both the nano text editor and the Python programming language. You are now ready to start developing Python apps within that containerized environment.

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



Source link

You may also like

Popular News

Popular Posts
Featured Posts
Recent Posts
Popular in Bitcoin
Trending Posts