Upload
justyna-ilczuk
View
345
Download
1
Tags:
Embed Size (px)
Citation preview
Justyna Ilczuk,Senior Software / DevOps Engineer
at
Speaker
A scalable backend that helps developers build complex apps
with only front-end code.http://www.syncano.com/
Docker - An open platform for distributed applications for developers and sysadmins.
* Powered by Linux Containers.
Build, Ship and Run Any App, Anywhere
Why?
Build Dev Environment than resembles production environment
- avoid strange bugs from dev/prod mismatch
Why?
Installing dockerized services is trivial
- You need a Postgres in version 9.4? Or redis, or Rabbitmq, Elastic Search?
Just pull an image and start a container.
Docker pros
Unified build processDockerfile
FROM debian:latestRUN apt-get update && apt-get install tmuxCMD tmux
$ docker build -t my_image .
Docker pros
Docker image format, portability, hub$ docker pull organization/image_name$ docker run -it organization/image_name command$ docker push me/my_image
Docker pros
Fast, starting container in 0.2 s
$ time docker run --rm ubuntu /bin/echo hello worldhello worlddocker run --rm ubuntu /bin/echo hello world 0,02s user 0,01s system 9% cpu 0,271 total
Docker pros - summing up
● lightweight containers● unified build process (Dockerfile)● standardized images (Docker hub)● fast, starting container in 0.2 s● combining containers together● distributed apps, microservices
Docker cons
● works only on GNU/Linux (needs vagrant / boot2docker)
● new tool to learn● another layer of complexity & overhead -
vagrant + Docker vs developing natively on your machine
Docker + Vagrant
● Works everywhere● Possible to try new tech, new OSes
○ CoreOS○ Kubernetes○ Mesos○ etcd○ Consul
● Distributed apps on your laptop
Docker CLI - the most important command
Running containers$ docker run --rm ubuntu echo “Hello docker”$ docker run -d -p 8080:80 nginx$ docker run -it -v `pwd`:/app -p 8000:8000 my_app
Docker CLI - checking state
Checking state of containers$ docker ps$ docker images$ docker logs my_container$ docker top my_container
Docker CLI
https://docs.docker.com/reference/commandline/cli/$ docker --help$ man docker
37 commands (for everything and more)
https://www.flickr.com/photos/pasukaru76/9824401426/in/photolist-9DE7Wa-cd6Wxf-dLkpKN-bW4iP-6TfKoP-okpdNP-fY9Cgu-8SBNJB-7vgLWL-a5sj6k-3SUkNL-koVXTM-8vs4F6-EmbdC-6w5kAz-i9E5k-878gAY-e88nnZ-9dDY7N-4uNsCX-7iuh42-fMEpmV-pybGg-bF1XGL-6cyxFq-tauEV-7zWj8-eewWz-a24hkr-4EjNgb-o4yuXd-f4PmxD-9bCZC5-e69XkS-dgEs3y-4jYxpy-6Qfw98-aB4Vgf-4gm9N6-jySVXM-dVJKrK-cu4nm3-jN6RPH-8W5ooc-4pAwWe-8TpRWe-77os7A-5256km-3NdDg2-6KipNW
Docker Compose
● Define your containers in simple yaml file.● Compose container together.● Manage group of containers with single tool.
Docker Compose - configdocker-compose.yml
redis: image: redis volumes: - /var/docker/redis:data ports: - "6379"web: build: . ports: - "80:8080" links: - redis:redis volumes: - .:/app environment: - VARIABLE=value
Docker Compose - configweb: build: . ports: - "8090:8080" links: - redis:redis volumes: - .:/app environment: - VARIABLE=value
Docker Compose
https://docs.docker.com/compose/https://docs.docker.com/compose/yml/https://github.com/docker/composeExample:http://www.syncano.com/configuring-running-django-celery-docker-containers-pt-1/
Updating images● Developers Bob and Alice work on an App.● They use docker-compose to run App● Bob adds new feature that requires Dependency X to be
baked into Docker image● He updates the requirements.txt file that is used in
Dockerfile and rebuilds his image
Updating images● Cool feature is merged to trunk● Alice pulls changes● Alice starts docker-compose and app breaks, because
of missing dependency in the container
Technical of people problem?
Should Alice remember to run `docker-compose build`, `docker-compose rm` and `docker-compose up` after each pull?
Good ol’ Makefilerun : build
docker-compose up -d
build : .built
.built : requirements.txt Dockerfiledocker-compose buildtouch .built
stop :docker-compose stop
clean : stopdocker-compose rmrm .built
test : .builtdocker-compose run web ./run_tests.sh ${ARGS}
.PHONY : run build clean stop test
Good ol’ Makefilerun : build
docker-compose up -d
build : .built
.built : requirements.txt Dockerfiledocker-compose buildtouch .built
Ups… something went wrong.
Building image failed.- it stops at layer that failed- starts from the last correct layer (cache)
Ups… something went wrong.
App in containers behaves in a strange way:Logs and errors- logging to stdout- logging to volumes- logging straight to Centralized Logging- logging to sentry
Ups… something went wrong.
https://github.com/slafs/sentry-docker <3
Ups… something went wrong.
Operating on a live patient -Debugging running containers
- no need for ssh- … no need for nsenter- $ docker exec -it my_container bash