AWS

Docker Overview with AWS ECS and Fargate

Hi Guys, we will be talking about Docker in this blog , as in the last blog we briefly touched this topic.

  • Docker Overview
  • Where do we store docker images
  • Docker vs Virtual Machines
  • ECS and Fargate pricing in AWS
  • Docker Flowchart
  • Docker Installation
  • Basic Docker commands

Docker

  • Docker is a software development platform to deploy apps.
  • Apps are packaged in containers that can be run on any OS.
  • Apps run the same, regardless of where they’re run.
    • They can run on any machine
    • No compatibility issues.
    • Predictable behavior
    • Less work
    • Easier to maintain and deploy
    • Works with any language, any OS, any technology.
  • Scale containers up and down very quickly(seconds)

Where do we store Docker images

  • Docker images are stored in Docker repositories
  • Public repository https://hub.docker.com/
    • You can find base images for many technologies or OS on this repository:
    • Ubuntu
    • MySQL
    • NodeJs, Java
  • Private Repository Amazon ECR (Elastic Container Registry)

Docker VS Virtual Machines

  • Docker is a type of virtualization technology, but not exactly
  • Resources are shared with the host and you can have many containers on one server.
Example of Docker Architecture

ECS and Fargate Pricing

  • EC2 Launch Type Model:
    • We need to pay for the underlying EC2 , EBS, Application load Balancers, EFS
    • No additional charges for the ECS Service
  • Fargate Launch Type Model
    • We pay for the amount of vCPU and RAM for your application requests based on how many containers we have.
    • You can use On Demand and Spot Pricing.
  • Analysis on pricing vs EC2: Please check the following blog for in-depth analysis https://www.trek10.com/blog/fargate-vs-lambda

Docker Flow Chart

Flow chart on how Dockers file is made into Docker container is given below. To learn more , please refer to the following article where i have given reference to Docker Basics Going Serverless In AWS

Docker Installation :

You can download the Docker desktop for Windows from the following link : https://docs.docker.com/desktop/windows/install/

After the installation is done , you can start the docker desktop . Below is the screenshot of Docker Desktop

If you are getting the error message that Docker engine is failing to start, try disabling the WSL 2 backend.

Once the docker engine has started and you are signed in you will see the following screen:

Basic Docker commands

To verify if the docker installation is working fine, we can run the following command

docker run hello-world

This will start the Hello world container by grabbing it from the official Docker hub repository. The command is given above which Docker run followed by the image we want to run.

To check if there is any image present in our repository , you can run the following command:

  • docker image ls
  • docker container ls –Will list the containers present in the local repository . As you can see i have one container present in the repository.
  • docker container ls --all –Will all the containers , even the ones which are stopped. As you can see in the screenshot below.
  • docker search ngnix –will give you all the images on the docker hub. For example i am searching the Ngnix images. You will get the following result.
  • docker run --name my-nginx -P -d nginx –For creating a new container from an image on the docker.hub you can run the command mentioned above, where name represents the name of the container that you will be making , -P will map a random port on your local box to the port 80 on the container , -d we are starting this container as a daemon (in the background) , then finally the name of the image that you will be using to create the container . I am using the default image of nginx.
  • Once you the command , the docker client will search locally for the image and since locally it’s not available , the image will be downloaded from docker.hub as you can see in the picture below:
  • docker container ls–When you run this command again , you can see the container running below with the ID. The important thing to note is the port mapping which has been done. On my machine you can see the port 49153 has been mapped to port 80 on the container.
  • curl http://localhost:49153 —when you run the following command in the terminal you can view the homepage of our nginx web server.
  • docker rm 35a31b7e924c –To remove the container you can run the following command, where the ID is the container ID.
  • docker image rm 87a94228f133 –In a similar way you can remove the image as well by running the command given for your reference.

I hope this article helps you in understanding Docker a little better , Happy Learning 🙂

Categories: AWS, Cloud, Containers

Tagged as: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.