Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
DOCKERDOCKERGRUNDLAGENGRUNDLAGEN
NICO MAASNICO MAASPYTHONCAMP 2018PYTHONCAMP 2018
07/04/2018 www.nico-maas.de 1 / 28
WHO AM I?WHO AM I?Nico MaasMaster of ScienceIT [email protected]@nmaas87
07/04/2018 www.nico-maas.de 2 / 28
OVERVIEW (1/3)OVERVIEW (1/3)Introduction
VMs vs ContainerContainer TechnologyDocker ArchitectureImages / Container
07/04/2018 www.nico-maas.de 3 / 28
OVERVIEW (2/3)OVERVIEW (2/3)Workshop
Demo Docker BasicsDemo Dockerfiledocker-composeDocker Swarm
07/04/2018 www.nico-maas.de 4 / 28
OVERVIEW (3/3)OVERVIEW (3/3)Docker at Work
resin.iogogs.iodrone.io
07/04/2018 www.nico-maas.de 5 / 28
INTRODUCTIONINTRODUCTION
07/04/2018 www.nico-maas.de 6 / 28
VM VS CONTAINERVM VS CONTAINER
07/04/2018 www.nico-maas.de 7 / 28
MATRIX FROM HELLMATRIX FROM HELL
07/04/2018 www.nico-maas.de 8 / 28
CONTAINERCONTAINER
07/04/2018 www.nico-maas.de 9 / 28
DOCKER ARCHITECTUREDOCKER ARCHITECTURE
07/04/2018 www.nico-maas.de 10 / 28
IMAGES / CONTAINERIMAGES / CONTAINERImages
FilesystemR/OA whole repo is available on hub.docker.com
Containerrunning instance of a imageR/Wchanges to the container must be "saved" withdocker commit - which creates a new image withthe changes as a new layer07/04/2018 www.nico-maas.de 11 / 28
IMAGE ARCHITECTUREIMAGE ARCHITECTUREImages consists of LayersDo not build Images by hand (docker commit) - usea DockerfileEvery CMD in a Dockerfile creates a new LayerLayers are cached - also on Image creation - partsthat change o en should go to the end of theDockerfile - so that Docker does not need to rebuildeverything from 0Example for the layers: https://imagelayers.io/?images=microscaling%2Fimagelayers-api:latest,microscaling%2Fimagelayers-web:latest07/04/2018 www.nico-maas.de 12 / 28
WORKSHOPWORKSHOP
07/04/2018 www.nico-maas.de 13 / 28
BEFORE WE START...BEFORE WE START...
07/04/2018 www.nico-maas.de 14 / 28
DEMO DOCKER BASICSDEMO DOCKER BASICSdocker
Docker Helpdocker version
Versioninformationdocker container ps
Running containersdocker container ps -a
Running and stopped containers
07/04/2018 www.nico-maas.de 15 / 28
DEMO DOCKER BASICSDEMO DOCKER BASICSdocker container run nmaas87/docker-openwrtecho "Hello Pythoncamp 2018!"
Download image nmaas87/docker-openwert on"latest" Tag from hub.docker.com, spin up newcontainer and execute command echo "HelloPythoncamp 2018!
07/04/2018 www.nico-maas.de 16 / 28
DEMO DOCKER BASICSDEMO DOCKER BASICSdocker container run -d nmaas87/docker-openwrtping 127.0.0.1 -c 50
Run ping cmd in deattached Modedocker container ps
Running containers
docker container attach a4fAttach to running container
Container "dies" as soon as the running root process(PID 1, here ping) ends
07/04/2018 www.nico-maas.de 17 / 28
DEMO DOCKER BASICSDEMO DOCKER BASICSdocker container run -it nmaas87/docker-openwrt/bin/sh
Run interactive shell in containerCTRL + P + Q
Disconnect from shelldocker container ps
Running containers
docker container attach a4fAttach to running container07/04/2018 www.nico-maas.de 18 / 28
DEMO DOCKERFILEDEMO DOCKERFILEUsed to build a new Docker Image / "recipe"
https://github.com/nmaas87/docker-demo
07/04/2018 www.nico-maas.de 19 / 28
DEMO DOCKERFILEDEMO DOCKERFILEgit clone
cd docker-demodocker image build –t app .
Create a Docker Image "app" from Dockerfile inthe current directory (.)
docker container run -p80:80 appStart new container from "app", expose containerport 80 to port 80 of the PC
Access via browserChange app.py, rebuild the image and restart
https://github.com/nmaas87/docker-demo.git
http://127.0.0.107/04/2018 www.nico-maas.de 20 / 28
DOCKER-COMPOSEDOCKER-COMPOSEUsed to execute and build images more easily
docker-compose.ymlRun container "flaskapp", restart even if service /Docker dies, use image "app", bind pc port 80 tocontainer port 80 (HOST:Container)Start with docker-compose up (-d withdeattached Mode)http://127.0.0.107/04/2018 www.nico-maas.de 21 / 28
DOCKER SWARMDOCKER SWARMRedundant Cluster of Docker Nodes, self-healing,routing overlay networkCreate swarm
Create Swarm on "Master/Manager" node:docker swarm init --advertise-addrPrints a CMD similar to:
docker swarm join --token :2377Execute on other Docker nodesDone07/04/2018 www.nico-maas.de 22 / 28
DOCKER SWARMDOCKER SWARMCreate service
docker service create --replicas 1 --name pingernmaas87/docker-openwrt:trunk_x86 pingdocker.com
docker service lsdocker service inspect --pretty pingerdocker service ps pingerdocker service scale pinger=3docker service rm pinger
07/04/2018 www.nico-maas.de 23 / 28
DOCKER SWARMDOCKER SWARMUseful CMDs (on Manager!)
docker node lsdocker info
07/04/2018 www.nico-maas.de 24 / 28
REALLIFEREALLIFE
07/04/2018 www.nico-maas.de 25 / 28
GOGS / DRONE / MAVEN / JUNITGOGS / DRONE / MAVEN / JUNIT
07/04/2018 www.nico-maas.de 26 / 28
SYSTEMSSYSTEMSwww.resin.io
Uses Docker as Deployment Method for Apps oni.e. Raspberry Pi or other Platforms
www.gogs.ioGitlab clone written in Go, packed as Dockercontainer
www.drone.ioCI System, packed as Docker container, usesplugins and addons also packed as Dockercontainer, builds code in Docker containers andworks great with Gogs07/04/2018 www.nico-maas.de 27 / 28
QUESTIONS?QUESTIONS?Thank you for your attention :)
www.docker.com
www.play-with-docker.com
www.nico-maas.de
07/04/2018 www.nico-maas.de 28 / 28