Installing AWS CLI with Dockers

aditya goel
7 min readJan 12, 2022

--

In case you are landing here directly, it’s recommended to read through this documentation first.

In this series, we would demonstrate following aspects :-

  • Setting up Docker container with help of plain Docker-Image.
  • Installing simple softwares like GIT & JDK on container.
  • Installing softwares like sudo, curl, zip, unzip, python3 and python3.8-venv, aws-cli, sam-cli onto our container.
  • Generating custom image with work(i.e. softwares installed) being saved.
  • Pushing the custom image to our public DockerHub repository.

Step #1.) Let’s first go and search for the various Docker-Images being available on the DockerHub regards to the ‘Ubuntu’.

Step #2.) Let’s now download the above docker-image of ‘Ubuntu’ to our local machine :-

docker image pull ubuntu

Step #3.) Let’s now run the container from the afore-downloaded Docker-Image ?

docker container run -it ubuntu

Above one is the interactive command. The “-i” means interactive & “-t”means connects the container to the terminal. But just think of it as being where running this container interactively and results of it is, You can see that that it’s dropping me onto a command line.

Therefore, we could see that in the above snapshot, container did started with the ‘Ubuntu’ image and even we are now inside this container.

Step #4.) I want to install GIT inside the above Docker-container that we have spawned. Pl show the same.

apt-get update && apt-get install git

Step #5.) Next, let’s install any good version of JDK within our container :-

apt-get update && apt-get install -y openjdk-8-jdk

Step #6.) Next, let’s verify whether the JDK got installed successfully or not :-

javac -version

Let’s exit from our container now.

Step #7.) Next, we would preserve the above changes i.e. we would generate fresh Docker-Image from this running container.

docker container commit -a “Ubuntu + JDK + Git image” 98 ubuJdkGitAdityaImage

Note that, 98 is the container-id from which we are forming our new image.

Step #8.) Let’s see that, this container (that we recently exited) exists in the list or not :-

docker container ls -a

Well yes, this container has been exited.

Step #9.) Let’s now go ahead and remove the containers completely from our history :-

docker container rm <container_id>

Step #10.) Let’s now see, what all images we have with us :-

docker images

Note that, we have this image, which we recently formed by our own in above part of the blog.

Step #11.) Let’s now launch a fresh container from the above image :-

docker container run -itd <NAME_OF_DOCKER_IMAGE>
OR
docker container run -itd <DOCKER_IMAGE_ID>

Please note below crucial points :-

  • We had ran the container with “-i” option which means interactive mode.
  • We had ran the container with “-t” option which means, we shall connect to the container’s terminal as well.
  • We had ran the container with “-d” option which means, we shall run this container in detached mode.
  • In the fresh container that we just launched, observe that both GIT & JDK are already installed, as we did the same in it’s previous container from which we formed this image.

Step #12.) Let’s now exit from our freshly launched container and verify, whether our container is running or not :-

docker container ps -a

Well, yes our container is running, because we ran the container in detached mode.

Step #13.) Let’s now logon back to our freshly launched container(in above step) :-

docker container exec -it <CONTAINER_ID> bash

Step #14.) Let’s now install some softwares into our docker container :-

apt update && apt upgrade
apt install curl
apt install sudo
apt-get install zip
apt-get install unzip
apt-get install python3
apt install python3.8-venv

Step #15.) Let’s now download the AWS CLI, within our docker container :-

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

Step #16.) Let’s verify whether the package has been downloaded well :-

ls

Step #17.) Let’s now unzip the AWS-CLI package :-

unzip <PACKAGE_NAME>

Step #18.) Let’s now run the install program. The installer installs the AWS CLI at /usr/local/aws and creates the symlink aws at the /usr/local/bin directory. Using the -b option to create a symlink eliminates the need to specify the install directory in the user's $PATH variable. This should enable all users to call the AWS CLI by entering aws from any directory.

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Step #19.) Verify that the AWS CLI installed correctly.

aws --version

Step #20.) Next, we download the AWS SAM CLI zip file to a directory of our choice at our host OS and then copy the same to our docker-container :-

docker cp aws-sam-cli-linux-x86_64.zip 9090f8d966d0:/aws-sam-cli-linux-x86_64.zip

Step #21.) Observe that, in our container, the same file has been copied :-

ls

Step #22.) Let’s unzip the downloaded directory :-

unzip aws-sam-cli-linux-x86_64.zip -d sam-installation

Step #23.) Let’s verify whether the sam-package has been unzipped :-

ls

Step #24.) Let’s now install the AWS SAM CLI :-

sudo ./sam-installation/install

Step #25.) Let’s now verify the SAM installation :-

sam --version

Step #26.) Let’s now exit from our Docker Container and see the containers

docker container ps -a

Step #27.) Let’s now generate a final docker-image from this container, to which we recently exited.

docker container commit -a "ubun+jdk+git+aws_sam docker image" 9090f8d966d0 ubu-with-aws-enhanced-image-by-aditya

Note that, the name of the docker-image we specified is : “ubu-with-aws-enhanced-image-by-aditya”.

Step #28.) Let’s now see all the docker-images so far we have :-

docker images

Note that, we can very well see the Docker-Image, recently generated by us.

Step #29.) Let’s now login to DockerHub

docker login

Step #30.) One last step is to generate the tag with owner/image-name. The official images published are allowed to have just a name. And the way that we do that, what we don’t really rename it, we just apply a tag to it. We’ll do that with below command :-

docker image tag 80ae6e7c21e9 adityagoel123/ubuwithawsdockimage

Step #31.) Let’s now see all the docker-images so far we have :-

docker images

Note that, we can very well see that, both of docker-repositories are referring to the same Docker-Image.

Step #32.) At-last, we push this docker image to the repository :-

docker image push adityagoel123/ubuwithawsdockimage

Step #33.) Finally, we verify this from dockerhub , whether our image succesfully reached to the dockerhub:-

That’s all in this section. If you liked reading this blog, kindly do press on clap button multiple times, to indicate your appreciation. We would see you in next series.

References :-

--

--