Part 2



In Part 1 of this 5-part tutorial, we had set-up the CentOS-7 system and configured the Dockerfile.

In this part of the tutorial, we will create the docker image, using the Dockerfile configured in part 1 and then push this docker image to both AWS ECR and Docker hub.

AWS ECR is Amazon’s Elastic Container Registry for storing docker images. 

Docker Hub is a service provided by Docker for finding and sharing container images.

When we deploy the remote-host container on a Kubernetes cluster, we can pull this image from either AWS ECR or Docker hub.

Typically, container images are pushed to a single registry. However, in our tutorial, we have pushed to 2 different registries, so you know how to do it. Based on your requirements and deployment, you can push your containers to your desired registry. 



Step 4: Create the remote-host container



We will now build the “remote-host” container with the below cmd:

NOTE: The below command MUST be run in the same directory where the Dockerfile is kept.

Syntax: docker build -f <docker-file-name> -t <image-tag-name> .      (“.” Specifies to use all the necessary files from the current directory) ###

    • $ docker build -f Dockerfile -t remote-host .

The above cmd builds a new remote-host container.

Next we “tag” the container. The reason for tagging is, we make modifications to the container and each version of the container may have additional features or new specifications might have been added to the container. 

Syntax: docker tag <image:name> <image-tag>

    • $ docker tag remote-host remote-host:1.1

    • $ docker tag remote-host remote-host:latest

    • $ docker images              

The above command will show the docker images that you have created

REPOSITORY                                                     TAG                                   IMAGE ID       CREATED        SIZE

remote-host                                                       1.1                                   51ec9bc20270   5 months ago   110MB

remote-host                                                       latest                              51ec9bc20270   5 months ago   110MB

Note: The “IMAGE ID” highlighted above is the same for both containers, only the tags are different. 



Step 5: Create a new user in AWS IAM



Next, create a new user in AWS IAM “remote_host”. (You can create any username you want)

Login to the IAM console, and create a new user “remote_host”. (Note: since we already had a “remote_host” user, we created a new user “remote_user” just for illustration)

Click “Next” 

Click “Next

(Note: since we already had a “remote_host” user, we created a new user “remote_user” just for illustration)

Click “Create user

Assign 2 policies to this user:

S3FullAccess to take backups

ECR policy to use ECR repos

Next, download the access/secret keys for this user and store these carefully for future use. This action happens ONLY once, so make sure that you keep the downloaded “csv” file carefully. 



Step 6: Authenticate the user using awscli.



On the docker creator EC2 instance

    • $  aws configure

Enter the below details from the “csv” file downloaded after creating the “remote_host” user. 

AWS Access Key ID [None]: <Access-ID>

AWS Secret Access Key [None]: <Secret-key>

Default region name [None]: ap-south-1


Access-ID –> Access ID from the “csv” file. 

Secret Key –> Secret key from the “csv” file.

Region –> You can provide the region details you are using. 



Step 7: Create AWS ECR and push the image to the registry.



Create a new repository in AWS ECR –> Private –> name=”remote-host” –> Tag immutability = disabled

Next use the commands mentioned in the ECR repository to get the token and push the containers:

    • $  aws ecr get-login-password –region ap-south-1 | docker login –username AWS –password-stdin

Below is the output:

WARNING! Your password will be stored unencrypted in /home/jenkins/.docker/config.json.
Configure a credential helper to remove this warning. See
Login Succeeded

Run the command to build the image again if required. Build the image (run in dir where Dockerfile exists. Create image tag 1.1 & latest)

    • $ docker build -t remote-host .      

    • $ docker tag remote-host:latest   ## (Create image with tag remote-host:latest)

    • $ docker tag remote-host:latest ## (Create image with tag remote-host:1.1)

Push the images to the ECR

    • $ docker push

    • $ docker push

Now if you refresh your AWS ECR repository, you will see the images. 

AWS ECR image



Step 8: Create a Docker hub account and push the image to docker-hub.



Follow the instructions when creating a new account or if you already have an account, log in and complete the next set of steps mentioned below:

Once logged in create a new “Repository” .

Repository Name = remote-host      (You can provide any appropriate name)

Visibility = Public  

Click “Create”

Below is a screenshot of “Create repository” creation process:

Next, push the images to Docker hub

Push the images to docker-hub in the remote-host repository

    • $ docker push avangelstech/remote-host:latest  

    • $ docker push avangelstech/remote-host:1.1  



This completes part 2 of the tutorial, in which we created our customized docker image “remote_host”  and pushed that image to both AWS ECR and Docker hub. 



In part 3 of this tutorial, we will deploy the “remote_host” container in our Kubernetes cluster and take a manual backup of the WordPress MySQL database. 


Part 1 –> Creating customized docker images.

Part 3 –> Deploy the customized container on Kubernetes cluster