Docker introduction

35
Docker Introduction By Walter Liu 2014/08/25

description

Brief introduction of Docker

Transcript of Docker introduction

Page 1: Docker introduction

Docker Introduction

By Walter Liu 2014/08/25

Page 2: Docker introduction

Agenda

• What is Docker?• How to use Docker?• Miscellaneous– Pitfall during POC– Tips and tricks– Some references

Page 3: Docker introduction

What is Docker?

Page 4: Docker introduction
Page 5: Docker introduction

Difference with VM

Virtual Machines

Docker

Page 6: Docker introduction

Difference with VM

– Memory is acquired when needed.– Disk is acquired when needed. • (If use devicemapper has had 10 GB limitation)

– Some file system is readonly.• Need to use priority mode to change it, but be careful

about that. I destroyed the container during functional test.

Page 7: Docker introduction

Copy on writeFile System

Page 8: Docker introduction

What does Docker want to solve?

The Matrix From Hell

Page 9: Docker introduction

Many Payloads …...

• RHEL 4• CentOS 5• CentOS 6• CentOS 7• ……

Page 10: Docker introduction

Many Payloads …...

• C/C++• C/C++ libraries• Python2.3/2.4/2.6• Python Libs• Boostpython• Ruby• Php• Java• …..

Page 11: Docker introduction

Many Payloads …...

• Nginx• Apache• Uwsgi• Django• Bottle• …..

Page 12: Docker introduction

Many Payloads …...

+ our application

Page 13: Docker introduction

Many targets

• Your dev environment• Co-worker dev environment• QA test environment• Staging environment• Production environment• Customized environment

Page 14: Docker introduction

How do we want to use it?

• Same environment between RD and OPS.• Faster delivery• Run old Linux in new Linux environment.– OPS could upgrade system OS without worry if old

application’s env.– If 2 applications are bound together, by using Docker

their OS env could be upgraded at different time.• Upgrade host OS without changing application.

Page 15: Docker introduction

How others use it?

• Easy Application Deployment• Continuous Integration• Continuous Delivery• Platform-as-a-Service (PaaS)• Development Environments & Build Pipelines -

Spotify

Page 16: Docker introduction

Easy Application Deployment

Page 17: Docker introduction

Continuous Integration/Delivery

• Write code• Push to git• Jenkins is triggered to build container and test the

container.• If the test is successful, push to private docker

registry. (Continuous Integration)• Automatic pull newest docker image to

staging/production server and switch load balance from previous version. (Continuous Delivery)

Page 18: Docker introduction

Development Environments & Build Pipelines

Page 19: Docker introduction

Docker Requirement/Dependency

• Linux Kernel 3.8+– CentOS 6.5+ (CentOS 7 is recommended)– Ubuntu is officially recommended.

• AUFS Support– (Not in CentOS, need Kernel patch)

• Cgroups and namespaces (Kernel 2.6.38+)• lxc• xz-utils

Page 20: Docker introduction

HOW TO USE DOCKER?

Page 21: Docker introduction
Page 22: Docker introduction

Installation

• yum install docker-io #EPEL repo• service docker start• chkconfig docker on• Option:– Add a user to run docker as root.

Page 23: Docker introduction

Import Image

• From docker repository– CMD: docker pull centos

• From a tar ball– CMD: docker load centos-wcs-build-1000.tar

• From private docker repository

Page 24: Docker introduction

Run container

• docker run –it <image_id> /bin/bash• Run docker container as a service– Use supervisor is a good choice.– Check example https://github.com/Krijger/docker-cookbooks

– And http://docs.docker.com/articles/using_supervisord/

• Note: if the process terminated, the container is terminated too.

Page 25: Docker introduction

Mount volume in a container

• option: -v , could be used multiple times to mount multiple volume.

• syntax: – docker run -v <host_path>:<container_path> …..– docker run -v <host_path>:<container_path>:rw ….. – docker run -v <host_path>:<container_path>:ro …..

• Example: docker run –it –v /trend/wcs/ptn:/trend/wcs/ptn:ro <image_id> /bin/bash

Page 26: Docker introduction

Publish port

• Option: “-p" Could be used multiple times to publish multiple ports to host.

• syntax:– docker run –P …. # Publish all ports to host, it’s big P.– docker run –p <host_container_port> …. # random port– docker run –p <host_port>:<container_port> ….– docker run –p

<host_interface_ip>:<host_port>:<container_port> ….

• Example: docker run –P <image_id> "/trend/wcs/wcsd" "/trend/wcs/conf/wcs.config"

Page 27: Docker introduction

Dockerfile example

This is not correct.

Page 28: Docker introduction

MISCELLANEOUS

Page 29: Docker introduction

Pitfall during POC

• Use too old Linux kernel (CentOS 6.4)• Use priority mode– Crash the container, all commands printed core

dump.• Run IO-heavy job on devicemapper. (4x slow)• Host and container uid is not sync.– WORKAROUND: adduser –u 1000 –g 1000 wcs

Page 30: Docker introduction

Tips and tricks

• Kill all containers– docker kill $(docker ps -q)

• Remove contents of all containers– docker rm $(docker ps -a –q)

• Remove all images– docker rmi $(docker images -q -a)

• Inspect IP of the container that just ran,– CID=$(docker run -d -p 4321 base nc -lk 4321)– docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID}

Page 31: Docker introduction

Some References

• 使用 DEVICE MAPPER 插件来改变 DOCKER 容器的大小https://www.dockboard.org/resizing-docker-containers-with-the-device-mapper-plugin/

• WHY YOU DON'T NEED TO RUN SSHD IN YOUR DOCKER CONTAINERS?– http://blog.docker.com/2014/06/why-you-dont-

need-to-run-sshd-in-docker/

Page 32: Docker introduction
Page 33: Docker introduction

Backup slides

Page 34: Docker introduction

The problems

• OPS needs to do – Installation, – Dependency– Monitor

• Environment conflict• Environment diff between Dev and production

Page 35: Docker introduction