- Amazon Linux Ami Install Docker Windows 7
- Install Docker In Amazon Linux Ami
- Amazon Linux Ami Install Docker Download
- Amazon Linux Ami Install Docker Windows 7
The usage of Docker is growing more and more. Our daily development tends to depend on the container platform highly. But I found AWS Linux I recently launched does not have Docker engine as default. It is a frustrating situation even I just want to use Docker in AWS environment. Here is the process to install Docker engine in your AWS Linux. That article is written mainly for avoiding my memory lost :)
AMI IDs change per region and over time, our filters will just look for the latest from amazon. Afterward, we wire up our EC2 to the security groups and profile we created. This container needs to run docker containers, so we add a userdata script that installs both docker and docker-compose. Learn how to install Docker and docker-compose on Amazon Linux 2 (AMI) and build sample applications running on AWS EC2/Lightsail VM cloud server. LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us.
FYI: The AMI I used in this experiment is ami-0f9ae750e8274075b
. Amazon Linux 2.
But you need to prepend sudo
every time you run docker command. Please don’t forget to add ec2-user
to docker
group.
After you log in the instance again, you should be able to run docker command without any difficulty.
Thanks
Related Posts

In this project, we will be going through a complete guide on deploying a Docker Swarm load balancer on a multi-node Amazon EC2 cluster. This objective is achieved using various tasks that can be deployed using Docker’s command-line interface or python SDK API’s. The idea is to design a load balancer that can distribute the load on different worker machines, based on the inter-arrival of requests. Using this project, you can understand the complete Docker Swarm architecture and how it can be leveraged in Amazon EC2 Linux AMI instances.
The complete Github repo can be found here: https://github.com/abhinavcreed13/docker-load-balancer-ec2.
- Project Setup
- Terminal or Command-line Interface
- Amazon AWS admin account with console access
- Basic understanding of Python 3.7
- Basic understanding of R/Rscript 4.0
A web application has to be deployed in a containerized environment. A sample Java web application is provided in the image “nclcloudcomputing/javabenchmarkapp”. Theimage contains an application deployed on a Tomcat application server. The application performs a prime number check on a large number, placing a load on the CPU. It listens to port 8080. URL: http://
Using this java web application, we will be deploying the following docker architecture as shown below.
Before starting with our tasks, we need to first configure our local environment and also show how to enable docker swarm on Amazon EC2 instances.
Setting up Amazon EC2 Linux AMI instance (Manager Node)
Using your AWS account, you can create an Amazon EC2 Linux instance by using the following machine to ensure all the configuration shown below works correctly.
When your instance is running, connect it using SSH or direct client and install the following components as described below. If you are doing an SSH using .pem
file, make sure to change permission by executing chmod 400 <key_name>.pem
.
1. Open Required Ports
You can either open ports using AWS console GUI or using the below CLI commands.
Using the above commands, all the ports will be opened for traffic from outside.
2. Install Docker (Linux AMI)
We can easily install docker on Amazon EC2 Linux AMI instances using amazon-linux-extras
as shown using the below CLI commands.
If docker is installed properly and running, then you should see the following information in your EC2 SSH shell.
Great!! So, now you have running docker daemon on your Linux EC2 instance.
3. Install Python 3.7 (Linux AMI)
Again, we can install Python 3.7 using yum
which we will be using for docker python SDK as shown using the below CLI command.
4. Install R 4.0 (Linux AMI)
We will also be installing R 4.0 for generating ggplot2
graphs by dumping CPU and memory statistics of our load balancer in mongodb
. This can be installed using the below CLI commands.
5. Initialize Docker Swarm
Now, we will initialize docker swarm on our manager node, so that other worker nodes can be connected with our manager node. First, we need to get our ethernet address. This can be done using the below command.
Next, we can initialise the docker swarm using the above advertising address as shown below.
This command will provide the join token. You can save it somewhere. It will be used to connect the worker nodes.
6. Upload python scripts and create a virtual environment
Finally, we will upload our entire python SDK scripts package in our manager mode. The package can be found in this GitHub URL: https://github.com/abhinavcreed13/docker-load-balancer-ec2/blob/main/package/docker-project-aws.zip.
This package can be uploaded into our EC2 instance using scp
command as shown below.

Then, this package can be unpacked inside EC2 instance using an SSH client and python packages can be installed as shown below.
After everything is properly installed and uploaded, you should have the following files in your manager node.
Amazon Linux Ami Install Docker Windows 7
Setting up Amazon EC2 Linux AMI instance (Worker Nodes)
You can again use Amazon EC2 Linux 2 AMI machines to create 2 or more than 2 worker nodes as shown below.
Once your worker node is running, connect it via an SSH client and install the following components.
- Open the required ports using the commands as shown in the manager node setup.
- Install Docker using CLI as shown in the manager node setup.
- Install Python 3.7 as shown in the manager node setup.
- Join the Docker Swarm using the join token provided by the manager node.
- Upload python scripts package and create the virtual environment as shown in the manager node setup.
Once all your worker nodes are correctly added in the swarm, you can run docker node ls
command in your manager node and you should see an output like shown below.
This completes the setup. After this setup, you should have a running Amazon EC2 multi-node swarm cluster which can take tasks and distribute them across worker nodes. Now, we will do the required objectives.
In this task, we need to pull and run the Docker image “nclcloudcomputing/javabenchmarkapp”. We need to perform these tasks using the following methods:
- Command-line interface
- SDK or API
Using Command Line
The command-line interface can be leveraged using the SSH client of our manager node or a worker node since we are just pulling and loading the image. It can be achieved using below CLI commands.
Using Docker Python SDK
Similarly, we can achieve a similar task using Docker Python SDK by running the following script in our manager or worker SSH client (inside docker-project-aws
folder)
The script can be download from here: https://github.com/abhinavcreed13/docker-load-balancer-ec2/blob/main/task01.py.

It uses client.images.pull
to pull the image and then client.containers.run
to run the container.
In this task, we need to deploy a multi-service application based on the below architecture.
Using Command Line
This task can be achieved using the command line interface by leveraging docker-compose
functionality with stack deployment. We can use the following docker-compose.yml
for achieving this task:
This YAML file can then be deployed on the manager node using the following commands.
Install Docker In Amazon Linux Ami
Using Docker Python SDK
Similarly, we can also use the Docker python SDK to achieve this task. We will be using https://github.com/abhinavcreed13/docker-load-balancer-ec2/blob/main/task02.py python script to deploy this stack which can be provided with command line parameters for enabling more control. This script should be executed on the manager node using the below commands.
In order to deploy stack with SDK, we are using client.services.create
method with docker.types.EndpointSpec
and docker.types.ServiceMode
as shown in the snippet of task02.py
below.
After the stack has been properly deployed, it can be verified using docker service ls
command by running it on the manager node as shown below.
We can also see our stack using docker swarm visualizer which is deployed on HTTP 88 port. It can be accessed from outside using http://<public-ip-of-manager-node>:88
as shown below.
A load generator creates a load on the web application by calling its URL multiple times. This could be used to benchmark system performance. In this task, we will create a simple program which puts a load on the web application by calling its URL. The program should accept the following parameters (through command line parameters):
- URL to be called.
- Inter-Request time distribution (Normal, Poisson).
- Mean($mu$) and standard deviation ($sigma$) in case of Normal distribution. Lambda($lambda$) in case of Poisson distribution.
- Number of iterations of URL calls to be done before the program terminates.
This task can be achieved by creating a python script which can take the above-stated parameters using a command line and generate the required load. It can be achieved using the following commands by running it on the manager node.
The implementation of task03.py can be found here: https://github.com/abhinavcreed13/docker-load-balancer-ec2/blob/main/task03.py.
It is using urllib.request
to hit the provided URL. In addition, it is using random.expovariate(args.lamb)
for generating poisson inter-arrival request times and np.random.normal(args.mu, args.sigma,args.iter)
for generating normal inter-arrival request times.
Upon running the script, we can see how it generates the load on the web application as shown below.
In this task, we will be adding a docker monitoring tool by using image - “google/cadvisor”. This can be achieved by running the command using command-line or SDK. This tool should be added on all manager and worker nodes for collecting the required statistics of CPU and memory.
Using command line
Using Docker Python SDK
The implementation using python SDK can be found here: https://github.com/abhinavcreed13/docker-load-balancer-ec2/blob/main/task04.py.
Now, if we generate load using normal or Poisson distribution, it can be seen on cAdvisor UI hosted on HTTP 70 port as shown below.
Next, we will insert our benchmark results into the MongoDB database as deployed in our stack. We will generate a normal or Poisson distributed request load using different inter-arrival times. This can be easily achieved using our task05.py - https://github.com/abhinavcreed13/docker-load-balancer-ec2/blob/main/task05.py - script as shown below by running on the manager node.
Note: make sure google/cAdvisor is also running on worker nodes.
This script will generate the load and save the recorded statistics from cAdvisor API into the MongoDB database with container names as collections for our manager node.
Similarly, we need to record the stats of our worker nodes. By logging in to the worker node, we can get their stats using the same script with different parameters as shown below.
Once we have stored all the stats in our chosen database, we can get all the collections of our database using task05-store-collections.py - https://github.com/abhinavcreed13/docker-load-balancer-ec2/blob/main/task05-store-collections.py - script and create CPU and memory charts using our graphs.R - https://github.com/abhinavcreed13/docker-load-balancer-ec2/blob/main/graphs.R - script.
The graphs are created using ggplot2
library by connecting with provided MongoDB database. As an example of extracting CPU metrics from the database using R is shown below.
After R script is executed successfully, you should be able to see the following files inside the graphics folder as shown below.
Amazon Linux Ami Install Docker Download
These files are created for CPU and Memory statistics for each of the available containers on the manager and worker nodes. These graphs will show total CPU usage during the generation of the load for each of the application containers as shown below.
Similarly, they will also show the total memory usage during the generation of the load as shown below.
Amazon Linux Ami Install Docker Windows 7
Cheers!