15 - Containers on AWS ECS Fargate ECR EKS

Docker Introduction

awscontainersdockersaa-c03

Overview

Docker is a software development platform to deploy apps. It is a container technology: apps are packaged into standardized containers that can run on any operating system. Once containerized, an app runs the same way regardless of where it runs, on any machine, with no compatibility issues. Behavior is predictable, so there is less work and it is easier to maintain and deploy. It works with any language, operating system and technology.

Use Cases

Microservice architecture (a good keyword to remember), lift and shift of apps from on-premises to the cloud, and any time you want to run a container.


How Docker Works on a Server

  • A server (here EC2 instances, but it can be any server) runs a Docker agent, and containers are started from it.
  • One container may hold a Java app, another a Node.js app. The same container can run multiple times (multiple Java containers, multiple Node.js containers).
  • Databases such as MySQL can run in Docker too, so Docker is very versatile.
  • From the server's perspective, all of these are just Docker containers.

Docker Repositories

Docker images are stored in a Docker repository.

Repository Details
Docker Hub Public repository, very popular; base images for technologies and operating systems such as Ubuntu and MySQL
Amazon ECR (Elastic Container Registry) For private integration; run your private images there
Amazon ECR Public Gallery Public repository option on ECR

Docker vs Virtual Machine

Docker is a sort of virtualization technology, but not exactly. Resources are shared with the host, so many containers can share one server.

Aspect Virtual machine (e.g. EC2) Docker
Stack Infrastructure, host OS, hypervisor, then guest OS and apps Infrastructure, host OS (may be an EC2 instance), Docker Daemon, then lightweight containers
Isolation VMs do not share resources and are isolated (how Amazon offers EC2 to many customers) Containers cohabitate, can share networking and some data
Security More secure A bit less secure
Density Fewer containers share a server More containers on a single server

Docker vs virtual machine

Virtual machine (e.g. EC2) Infrastructure Host OS Hypervisor Guest OSApp Guest OSApp Isolated, no shared resources More secure, fewer on a server Docker Infrastructure Host OSmay be an EC2 instance Docker Daemon Container Container Container Resources shared with the host A bit less secure, more per server
Containers share the host through the Docker Daemon, so more fit on one server. VMs are isolated by a hypervisor.

Getting Started with Docker

  1. Write a Dockerfile defining how the container looks: a base Docker image plus added files.
  2. Build it, which produces a Docker image.
  3. Push the image to a Docker repository (Docker Hub, public, or Amazon ECR).
  4. Pull the image back from the repository.
  5. Run the image. A running Docker image becomes a Docker container that runs your code.

From Dockerfile to container

Dockerfile Docker imageafter build RepositoryDocker Hub or ECR Docker containerimage is running build push pull, run A running Docker image becomes a Docker container that runs your code.
Build, push, pull and run.

Docker Container Management on AWS

Service Details
Amazon ECS (Elastic Container Service) Amazon's own platform for Docker management
Amazon EKS (Elastic Kubernetes Service) Amazon's managed version of Kubernetes, an open source project
AWS Fargate Amazon's own serverless container platform; works with both ECS and EKS
Amazon ECR Stores container images

See 02-Amazon-ECS, 05-Amazon-ECR and 06-Amazon-EKS.


Questions & Answers

Q1: What is Docker?

Answer:

A container technology that packages apps into standardized containers that run the same on any OS or machine.

Q2: Where are Docker images stored?

Answer:

In a Docker repository: Docker Hub (public) or Amazon ECR (private, plus the ECR Public Gallery).

Q3: How do containers differ from VMs?

Answer:

Containers share the host's resources through the Docker Daemon, so more run on one server, but isolation is weaker than VMs on a hypervisor.

Q4: What turns a Docker image into a container?

Answer:

Running it. The flow is Dockerfile, build, push, pull, run.

Check yourself

Quiz

Flashcards

Click the card (or focus it), then use ← → to move and Space to flip.