Install Docker On Amazon Linux Ami

/ Comments off

Installing docker on Amazon Linux 2 is full of surprises which are not easy to deal with. I just wanted to test something within a container environment, so spun up a new EC2 instance from the following AMI:

Amazon Linux 2 AMI (HVM), SSD Volume Type - ami-0ded330691a314693 (64-bit x86) / ami-0c3a4ad3dbe082a72 (64-bit Arm)

After this Linux instance came up, I just did yum update to get all the latest stuff:

sudo yum update

All good so far.

Then I installed/checked yum-utils and grabbed the docker repo, and all good there:

My instance is on this AMI: amzn2-ami-hvm-2.0.20191116.0-x8664-gp2 (ami-01f14919ba412de34) I want to install docker following this document so here is the output of my commands: [email protected] $ sudo amazon-linux-extras install docker Installing docker Loaded plugins: extrassuggestions, langpacks, priorities, update-motd. As the Docker team advances with new features frequently, the Amazon Linux AMI repo (amzn-updates) Docker package is not always up to date, hence some latest features are not immediately available (e.g. When installing Docker with sudo yum install -y docker).

[[email protected] ~]$ sudo yum install -y yum-utils

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd

Package yum-utils-1.1.31-46.amzn2.0.1.noarch already installed and latest version

Nothing to do

[[email protected] ~]$ sudo yum-config-manager

> --add-repo

> https://download.docker.com/linux/centos/docker-ce.repo

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd

adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo

repo saved to /etc/yum.repos.d/docker-ce.repo

Now, it's time to install docker:

[[email protected] ~]$ sudo yum install docker-ce docker-ce-cli containerd.io

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd

Resolving Dependencies

--> Finished Dependency Resolution

Error: Package: containerd.io-1.2.13-3.2.el7.x86_64 (docker-ce-stable)

Requires: container-selinux >= 2:2.74

Error: Package: 3:docker-ce-19.03.12-3.el7.x86_64 (docker-ce-stable)

Requires: container-selinux >= 2:2.74

You could try using --skip-broken to work around the problem

You could try running: rpm -Va --nofiles --nodigest

and it failed.

So googled the error Requires: container-selinux and every stackoverflow post and blogs say to download the new rpm from some centos or similar mirror but it simply doesn't work, no matter how hard you try.

Here is the ultimate best solution which enabled me to get docker installed on Amazon Linux 2 on this EC2 server:

sudo rm /etc/yum.repos.d/docker-ce.repo

sudo amazon-linux-extras install docker

sudo service docker start

[[email protected]~]$ docker --version

Docker version 19.03.6-ce, build 369ce74

That's it. I hope that helps.

Note: This article was originally published here.

Docker

This tutorial explains, how to install docker on EC2 Instance. Before starting, let’s have some brief knowledge about Docker.

Docker is a platform that combines applications and its dependencies in the form of packages, called container. We can run multiple containers on a single Operating System. Containers are not Virtual Machines. Virtual Machines requires Operating System to run applications, but containers do not. As containers don’t need an Operating System, it takes very little time to start and hence it is very faster than Virtual Machines.

Also Learn: How to install Ansible on Amazon Linux(EC2 )

and Launching Amazon Linux EC2 Instance

Let’s Install Docker on EC2 Instance

In this tutorial, we will use Amazon Linux to install docker. Amazon Linux/Amazon Linux2 is the Linux Operating System used in EC2 Instance.

Step 1– Log to Linux EC2 Instance and update it.

$ sudo yum update -y

Step 2– Install docker using Yum command

$ sudo yum install docker -y

Step 3– Start Docker Service

$ Service docker start

Step 4– Check docker Version.

$ docker -v

Basic Configuration (Creating Docker File / Running Docker Image)

After you install docker on ec2 , let’s have some basic setup for Docker.

Step 1 – Create a docker file

Dockerfile is a text file where we write instructions to build an image.

Create a folder name Images on the Amazon Linux box.

Install Docker On Amazon Linux Amiibo

$ mkdir images

Move to folder images

Install Docker On Amazon Linux Amika

$ cd images

Create a file name Dockerfile inside images folder

$ nano Dockerfile

Put the content in the following way inside the Dockerfile.

FROM Ubuntu ( It will use the Official image Ubuntu to build your image)

MAINTAINER chandan <[email protected]>

( It sets the Author field of the generated image)

RUN apt-get update ( It will update the image at the time of Build)

CMD [ “echo”, ” Hello World ……….! “] ( It will run echo command when we run the docker container image)

Please also readHow to install docker on ec2 Instance(Windows)

AmazonInstall docker on amazon linux ami

You may also likeInstall Docker on Ubuntu using Script

Step 2– Run the docker build command to build the image.

$ docker build .

Note : ( . command is used when you are inside images folder where Dockerfile is present, alternatively you can put the docker file absolute path like /home/ec2-user/images/Dockerfile)

You can run the following command as well to Name and tag your Image. Here myimage is the Name and 01 is Tag of the image.

$ docker build -t myimage:01 .

Step 3– See the Docker Images after build

$ docker images

Step 4 – Run the docker image

$ docker run 07deaa33585e

Here 07deaa33585e is the IMAGE ID that can be seen in docker images command.

You can see here, it executed the echo command as soon as we run the docker image. In the same way, we can run any script, commands or any application by running a docker image.

Click to tweet this tip !

I hope you enjoyed this tutorial and learned to install docker on ec2 instance (Amazon Linux). If you think this is really helpful, please do share this with others as well. Please also share your valuable feedback, comment or any query in the comment box. I will really happy to resolve your all queries anytime.

Thank You

If you think we helped you or just want to support us, please consider these:-

Connect to us: FacebookTwitter