Transcript
Page 1: Deployment Automation with Docker

Deployment Automation

Egor [email protected]

Platform ArchitectGlympse, Inc.

Page 2: Deployment Automation with Docker

Docker is

AWESOME

Page 3: Deployment Automation with Docker

Docker is not intended to

solveEVERYTHING

Page 4: Deployment Automation with Docker

Problem

Source Code

Build Config

Environment

Dependencies

Runtime Config

Compute Instance

Page 5: Deployment Automation with Docker

Terminology

Docker Registry

Docker Image

Docker Daemon

Docker Instance

Docker Image

Docker Container

*

*

1

1

1

*

Storage backend

Local volume, S3, etc.

Registry Instance

Docker Client

Docker Client

Page 6: Deployment Automation with Docker

Installation

Docker Daemon

Linux

Docker Client

MacOS

Docker Client

Docker Daemon

VM running Linux

$DOCKER_HOST

Page 7: Deployment Automation with Docker

Flow

Docker Registrypush image_x

dev. box / Jenkins / CD

InstanceSource Code

Env / Deps

Configuration

Instance

pull image_x

Docker Image

run image_x

1 2

3

Page 8: Deployment Automation with Docker

Image Anatomy

Base Image

Updates

Dependencies

Application

Base Image

Updates

Dependencies

Application

Images

bootfs

Base ImageImage

Image

Image

r/or/or/or/or/o

App I/O

r/w

Container

Union file systemUnion mount

Parent

Page 9: Deployment Automation with Docker

Linux Containers (LXC)

OS Kernel

...

Con

tain

er

Con

tain

er

Con

tain

er

Docker daemon

Multi CPU/core box

cgroups

Resource isolation● CPU● memory● disk I/O

Namespace isolation● process tree● network● user ids● mounted file systems

OS Kernel

Docker

...

Con

tain

er

Con

tain

er

Con

tain

er

There is no virtualization involved when

software runs within containers.

(2007)

Page 10: Deployment Automation with Docker

Docker Registry

Docker Registry

Docker Image

dev / test / staging / production

*1

Storage backend

Local volume, S3, etc.TCP-based APIREST API

REST API

Docker Daemon

Jenkins/CD/automation

software

ContainersContainersContainers

Page 11: Deployment Automation with Docker

Registry Options

Docker Hub

Docker daemon

Public Images

Private Images

Private Registry

Private Cloud

default

Page 12: Deployment Automation with Docker

Private Registry

Registry container

nginx container

Docker Hub Not secure / unauthenticated

pull registry

pull nginx

SSLBasic Auth

InternetVPC

Docker Instance

S3 Bucket

Page 13: Deployment Automation with Docker

Starting Registry

docker run --restart=always -e SETTINGS_FLAVOR=s3 -e AWS_BUCKET= registry.docker.enterprise.glympse.com -e STORAGE_PATH= /storage -e AWS_KEY=AKIA... -e AWS_SECRET= OEJ0... -e SEARCH_BACKEND=sqlalchemy -p 5000:5000 -d registry

Registry container

Docker Instance

S3 Bucket

docker pull registry

:5000

:5000

Page 14: Deployment Automation with Docker

Detailed Flow

Image

build

Source Code

Registry

Image

Container

tagpush

pull

run

rm

rmi

start

Daemon

ps

images

...

stop

Page 15: Deployment Automation with Docker

FROM ubuntu:14.04

# Install Python SetuptoolsRUN apt-get install -y python-setuptools

# Install pipRUN easy_install pip

# Bundle app sourceCOPY . /src

# Add and install Python modulesRUN pip install -r /src/requirements.txt

# Set default container commandENTRYPOINT ["python"]

# Run the appCMD ["/src/server.py"]

Dockerfile /projectrequirements.txtserver.pyDockerfile

/usr/user/src

req-s.txtserver.py

ubuntu

python-setuptools

pip

requirements

Project source code

docker build -t image_x .

image_x

Image Storage

<none>

IMAGECHARACTERISTICS

DeterministicIndependent

docker run ... image_x

/usr/user/src

req-s.txtserver.py

ubuntu

...

<none>

<none>

<none>

Container r/w layer

Running Container

Page 16: Deployment Automation with Docker

Walkthrough

docker build -t IMAGE_NAME .

docker tag IMAGE_ID REGISTRY_URL:PORT/IMAGE_NAME:TAG

docker push REGISTRY_URL:PORT/IMAGE_NAME:TAG

docker pull REGISTRY_URL:PORT/IMAGE_NAME:TAG

docker run --restart=always -d -p HOST_PORT:CONTAINER_PORT IMAGE_NAME:TAG

Build image from source

Tag image appropriately

Push image to the registry

Pull image from the registry

Run container based on the image

Dev boxJenkinsCD

ProdStagingTest

Page 17: Deployment Automation with Docker

Container Configuration

Docker Instance

ContainerContainer portHost port

/src/dir

Host FS

Container FS/opt/dir

Configure port mapping

docker run ... -p HOST_PORT:CONTAINER_PORT

docker run ... -v HOST_DIR:CONTAINER_DIR

Mount a host directory as a data volume

Page 18: Deployment Automation with Docker

Instance

En Route Deployment Demo

Admin Consoleweb app

Backend Appapi servers

LB

Instance

App

LB

Instance

Instance

...

DB

Page 19: Deployment Automation with Docker

feature/ec2_demo

user nameuser@email Logout

Admin Console

ip:pid

API Servers

/any/thing

http://169.254.169.254/latest/meta-data/public-ipv4

OM

{ ... box: { ip: IP, pid: PID }}

os.getPid()

Page 20: Deployment Automation with Docker

Instance Template

Dockerized Application

App PORT -> Instance PORT

Instance Dockerdaemon

ContainerConfiguration

environment variables

Registrypull image

aws ec2 run-instances ...

EC2Connection.run_instances(...

CloudFormationConnection. create_stack(...

{ "Parameters" : { ... }, "Resources" : { ... }, "Outputs" : { ... }}

AWS CLI

AWS SDK

AWS SDK

CloudFormation

Page 21: Deployment Automation with Docker

Cluster Operations

Load Balancer

App InstanceApp Instance

App InstanceApp Instance

App Instance

api - tracking - engineweb - tracking - admin

type NS app

cluster_createcluster_deletecluster_details

cluster_launch_instancecluster_terminate_instance

cluster_register_instancecluster_deregister_instance

Cluster StructureClusters

Operations

https://github.com/Glympse/CommonTools/tree/master/DockerCluster management scripts can be found here

Page 22: Deployment Automation with Docker

Next● Orchestration ● SSL / Authentication● Configuration (identity, networking)● Monitoring (health checks)● Continuous delivery


Top Related