How to Use AWS CLI in Docker Container ?
Last Updated :
24 May, 2024
The AWS Command Line Interface (CLI) is a powerful tool that allows users to interact with AWS services directly from the terminal. Integrating AWS CLI within a Docker container can significantly streamline workflows, especially for development and deployment processes that rely on cloud infrastructure. This article will guide you through the steps of installing and configuring AWS CLI in a Docker container, ensuring a consistent and portable environment for managing AWS resources. Whether you're a developer or a system administrator, mastering this setup will enhance your efficiency and productivity.
What is AWS CLI?
The AWS Command Line Interface (AWS CLI) is an open-source tool that enables you to interact with AWS services using commands in your command-line shell. With minimal configuration, the AWS CLI provides you with the ability to quickly and easily access the same functionality as the browser-based AWS Management Console from the comfort of your terminal program.
What Is Docker Container?
A Docker container is a runtime instance of an image. Allows developers to package applications with all parts needed such as libraries and other dependencies. Docker Containers are runtime instances of Docker images. Containers contain the whole kit required for an application, so the application can be run in an isolated way. For eg.- Suppose there is an image of Ubuntu OS with NGINX SERVER when this image is run with the docker run command, then a container will be created and NGINX SERVER will be running on Ubuntu OS.
Steps To Install AWS CLI in Docker Container
To install the AWS CLI within a container that is running Docker, follow the instructions listed below.
Step 1: Pull the sample image from the Docker Nginx image.

Step 2: Use a Docker container to run the Nginx image. To obtain the docker container's ID after running, use the "docker ps" command.
Step 3: The `docker exec` is a docker command that allows users to run commands inside a running Docker container, bridging the gap between the container environment and the host system. This command opens up possibilities for troubleshooting and debugging. It performs administrative-related tasks within a live container.
docker exec -it <container ID> bin/bash

Step 4: Download and install AWS CLI using the following commands as shown in the image below. Inside the docker container
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Step 5: Since it was a Docker container, there won't be an unzip command available. To install that command, use the ones listed below.
sudo apt update
sudo apt install unzip

Depending on the situation, "sudo" can be utilised. In this case, however, I wasn't using it because I was already logged in as root to a Docker container.
Step 6: Verify weather AWS CLI installed or not using the following version.
aws --version


Steps To Use AWS CLI in Docker Container
Follow the steps mentioned below to use AWS CLI indocker container.
Step 1: Use the following command to configure the AWS (Amazon Web Services) credentials by which was cli will interact to aws account.
aws configure

After executing the above command it will ask for AWS Access key and secret key to know how to generate them refer to the
Step 2: Configure AWS CLI to Disable Paging: You can configure the AWS CLI to disable the use of a pager, which will prevent it from attempting to use less or any other pager program. You can do this by setting the AWS_PAGER environment variable to an empty string:
export AWS_PAGER=""
Step 3: The output of the command shows that there is one running instance. Here are some of the details about the instance:
- Instance ID: i-0ff86c22f8ed01eef
- Image ID: ami-04b70fa74e45c3917
- Instance Type: t2.micro
The Instance ID is a unique identifier for the instance. The Image ID is the ID of the Amazon Machine Image (AMI) that was used to launch the instance. The Instance Type is the type of EC2 instance that you launched. In this case, the t2.micro is a burstable micro instance. Burstable instances are a type of instance that provide a baseline level of CPU performance, with the ability to burst to higher levels for short periods of time.

AWS CLI in Docker Container - FAQs
What is Dockerfile Extension?
Dockerfile is the source code of docker image and basically there is no extension for Dockerfile or you may use â.dockerfile or .Dockerfileâ they can be used but they are not mandatory. The standard file name is Dockerfile.
Dockerfile Copy Directory
The COPY command or instruction in the dockerfile is used to copy the directories from docker host to the docker image.
Dockerfile vs Docker Compose
- Dockerfile:Â Dockerfile consists of all the steps that are required to create docker image. Dockerfile consists of base image and the all remaining environmental variables.
- Docker Compose:Â YAML file consists of multi-container applications.Simplifies the orchestration and configuration of Dockerized applications by specifying services, networks, and volumes.
Similar Reads
How to Use AWS CLI in Docker Container ?
The AWS Command Line Interface (CLI) is a powerful tool that allows users to interact with AWS services directly from the terminal. Integrating AWS CLI within a Docker container can significantly streamline workflows, especially for development and deployment processes that rely on cloud infrastruct
4 min read
Web Page Hosting in Docker Container Using AWS
The operating system (OS) libraries and dependencies required to run the application source code which is not reliant on the underlying operating system (OS) included in the Dockerfile, which is a standardized, executable component. Programmers may design, distribute, launch, run, upgrade, and manag
6 min read
How To Use SSH Keys Inside Docker Container?
SSH key is a credential used for remote access of servers without using any type of username and password and Docker is a containerization tool used to encapsulate the application with its dependencies into compact units called docker containers. In this guide, I will first discuss what is SSH key a
5 min read
How to Automate Docker Container Updates?
In this fast-paced software development environment, the current status of application security should be important to the DevOps team. Docker is a widely used platform for application containerization, which gives a flexible and efficient way in managing application dependencies and deployments. Ho
9 min read
How To Run A Cron Job Inside A Docker Container ?
In the containerization world, management of resources and scaling the applications are necessary to make our services effective and user-friendly for the users. In this, the cron job helps in a significant way with facilitating features such as isolation, portability, scalability, and resource mana
5 min read
How to Remove Docker Containers
Docker is a platform that provides a set of PaaS (Platform as a Service) products that help developers containerize applications, allowing them to run consistently across various supported environments. The core component of Docker is Docker Engine which consists of: Docker Daemon: The process respo
2 min read
How to Setup Jenkins in Docker Container?
Setting up of Jenkins in a docker container provides the facility of streamlining the CI/CD with scalability and consistency. It also helps for attaching the worker nodes as slaves and run the build jobs over their. In this article, we will guide you through the process of deploying jenkins in a Doc
6 min read
How to Link Multiple Container in Docker ?
Docker is a free software created by Docker Inc. and it enables clients to create free and confined environments where the users can deploy their applications. A container is a standard unit of software that packages up code and all its dependencies from one computing environment and runs it quickly
2 min read
How to Deploy a Flask Web Server in Docker Container using AWS?
In the current digitized era, web servers are essential as they stand for various online applications and sites. Web servers run stealthily the scenes to give the devices needed information and functional facilities irrespective of whether surfing on the internet, using a mobile app, or cloud facili
10 min read
How to Access Docker Container From Browser
In present-day software advancement, Docker is significant for building, shipping, and running applications. It ensures that applications and their dependencies operate seamlessly across environments by enclosing them in containers. This is especially helpful for web applications that need to be tes
7 min read