Collageb by the author.

~Setting up an Environment to run Docker~

Asonti Ginn
Women in Technology

--

Today’s Goals

~ Create an Ec2 Instance.

~Connect to the EC2 instance and install docker.

~ Optional: Connect to your docker environment through VS Code.

Key Terms

~EC2 Instance: Stands for Elastic Compute Cloud which is a virtual server inside the AWS Cloud.

~ VS Code: A code editor and it offers many extensions to make VS Code run like an IDE.

~ Ubuntu: Ubuntu is a free Open-Source Linux distribution.

~ Sudo: Allows you to run commands as if you are the root user in a terminal.

~ Docker: With docker you can build, update, and run containers.

Prerequisites

~ An AWS Account.

~ Basic terminal knowledge.

Creating an Instance

Begin by logging into your AWS account and going to EC2 in the console.

Launch an instance.

Add a name and set the AMI to Ubuntu.

We want our project to remain free so set your instance to t2.micro.

Create a new key pair, this will download to your downloads folder on your computer.

When creating the new key pair keep the key pair type RSA and .pem.

We will keep our instance inside our default VPC, but we need to create a new security group. This security group needs to allow SSH traffic. If you want this security group to be named, select edit at the top right corner of the box.

Once you finish your Network settings you can launch your instance.

Before we go into our instance, we need to check some security settings.

Click on your instance security settings you need 2 inbound rules. One for SSH and the other for All traffic. Your SSH should be from Anywhere and All traffic should be set to your IP address.

If your settings are not like mine select the security group button in the inbound rules and add the other rules.

Install Docker

Wait until your instance no longer displays pending and the status changes to running. Click on your instance and select ‘Connect’.

We are going to SSH into our environment, so under SSH Client, copy the example.

On your computer enter your power shell. You need to cd to the directory that is holding the key pair you created. If you did not move your keypair it will automatically go to your downloads folder.

In power shells, enter the following command to change to your downloads folder.

cd Downloads

If you did move your keypair, locate the folder on your computer, copy the path and type the following command.

cd <YOURPATH>

After entering your folder, we now want to paste in the SSH command we copied earlier. It will ask about a fingerprint type ‘yes’.

You should now be inside your Ubuntu instance; we want to make sure everything is updated so let's call an update.

sudo apt-get update -y

Time to install docker, paste the following commands.

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

To be sure docker is installed correctly run docker version to tell you the version of docker that is installed.

sudo docker version

You have now installed Docker on your EC2 Instance.

Optional: VS Code

You can download Visual Studio Code in your desktop's app store.

Inside of VS Code we need to install certain extensions to make our Docker experience a whole lot simpler. Select the extensions tab on the left side to begin downloading everything we need.

Download all of the following extensions:

~ Docker

~ Git lens

~ Remote SSH

~Kubernetes

~ YAML

~ Remote Development

After installing all of the extensions, in the top left corner select file and open a folder.

In your files you need to locate your .ssh folder, this folder is usually located in the users folder. To find the users folder select your local drive. Then inside users, click the .ssh, and use this folder to open in VS code.

If you receive this pop up about trusted authors, you can trust the authors of your own files.

We need to add a file to our folder, this will be our config file.

We will set this file up to enable us to connect to our instance in VS Code.

You will need to paste your instance IP as well as the path to your keypair in the code below.

#DOCKER FILE
Host DOCKER
#Change your IP Address every time you connect
HostName <YOURIPADDRESS>
User ubuntu
IdentityFile C:\<YOURPATH>

NOTE: EVERY TIME YOU WANT TO ENTER YOUR INSTANCE, YOU MUST PUT YOUR NEW IP ADDRESS, YOU WILL NOT HAVE TO RETYPE THE ENTIRE FILE.

Save your file and select this button in the bottom left corner.

This will put a prompt on the top of your screen select ‘Connect to Host’.

In our config file we specified that our Host is Docker. An entire new VS Code will open and put you inside our Ubuntu instance.

When it asks for your platform select Linux and if a continue option appears do select continue.

Once everything is loaded your bottom left corner should now show that you have ssh into you docker environment.

On the top of your screen open a new terminal.

Run the command to check your docker version again.

sudo docker version

As you can see you have successfully created a docker environment.

Want to try some cool things with docker? Check out my beginner friendly article where I help you make Docker containers and install things in the Container. installing-apache-in-a-container

For more, easy to follow articles, follow me on Medium!

--

--

Asonti Ginn
Women in Technology

Hey! I am taking you on my Cloud engineering journey with easy to follow, how-to articles. All provided with an under 10-minute read and PLENTY of pictures!☁️