Creating a Dockerfile
Let's begin with the first step of creating our AWS Docker setup.
We'll cover the following
The first step of any Docker setup is to write its Dockerfile. In the Dockerfile, we’ll specify all the things we need in our container. There are three basic steps to always consider:
- Make sure your container is running Ubuntu.
- All frameworks required for your setup are installed in the Dockerfile.
- Any code you need to run is copied into the container.
Dockerfile
Below, we have provided a basic Dockerfile for AWS CLI. We’ll go through it step-by-step.
# Base imageFROM ubuntu:20.04# Installing prerequisite packagesRUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get install -y tzdata keyboard-configurationRUN apt-get -y install curl unzip groff less# AWS CLI installation commandsRUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"RUN unzip awscliv2.zip && ./aws/install
-
FROM ubuntu:20.04
- Specifies the base image of our container. Theubuntu
images are officially supported on Educative. However, other Debian images can also work. -
RUN DEBIAN_FRONTEND...
- Installs a few prerequisite packages through simpleapt-get install
commands."noninteractive"
is used to ensure that the image build process does not hang on a prompt. -
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- Saves the official AWS CLI Linux installation in a zip file. -
RUN unzip awscliv2.zip && ./aws/install
- Unzips the zip file and runs the installation.
Rule of thumb: The installation commands for any framework can be found all over the internet. The trick is to simply copy those commands into your Dockerfile.
Tarball
Once the Dockerfile is ready, you need to compress it into a tarball in order to upload it to your course.
tar -czpf aws.tar.gz Dockerfile
This creates a tarball named aws.tar.gz
. You can find the file below:
Uploading the Tarball
This is where you integrate your Docker setup into your course. Navigate to the main course editor page and find the Docker Container section:
The Change Dockerfile button lets you upload the tarball. Click on Save on the top-right to begin the building process! Once the image is built successfully, you will receive the following prompt:
We are almost at the finish line. Head to the next lesson to start using AWS on Educative!