Docker in everyday development
- 2. 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/
- 4. Docker - An open platform for distributed
applications for developers and sysadmins.
* Powered by Linux Containers.
Build, Ship and Run
Any App, Anywhere
- 13. Docker pros
Unified build process
Dockerfile
FROM debian:latest
RUN apt-get update && apt-get install tmux
CMD tmux
$ docker build -t my_image .
- 14. Docker pros
Docker image format, portability, hub
$ docker pull organization/image_name
$ docker run -it organization/image_name
command
$ docker push me/my_image
- 17. Docker pros
Fast, starting container in 0.2 s
$ time docker run --rm ubuntu /bin/echo hello world
hello world
docker run --rm ubuntu /bin/echo hello world 0,02s user 0,01s system 9% cpu
0,271 total
- 18. 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
- 19. 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
- 21. Docker + Vagrant
● Works everywhere
● Possible to try new tech, new OSes
○ CoreOS
○ Kubernetes
○ Mesos
○ etcd
○ Consul
● Distributed apps on your laptop
- 24. 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
- 25. Docker CLI - checking state
Checking state of containers
$ docker ps
$ docker images
$ docker logs my_container
$ docker top my_container
- 31. Docker Compose
● Define your containers in simple yaml file.
● Compose container together.
● Manage group of containers with single tool.
- 33. Docker Compose - config
docker-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
- 34. Docker Compose - config
redis:
image: redis
volumes:
- /var/docker/redis:data
ports:
- “6379”
- 35. Docker Compose - config
web:
build: .
ports:
- "8090:8080"
links:
- redis:redis
volumes:
- .:/app
environment:
- VARIABLE=value
- 36. Docker Compose - commands
$ docker-compose build
$ docker-compose up
$ docker-compose ps
- 40. 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
- 41. 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
- 42. Technical of people problem?
Should Alice remember to run `docker-
compose build`, `docker-compose rm` and
`docker-compose up` after each pull?
- 44. Good ol’ Makefile
run : build
docker-compose up -d
build : .built
.built : requirements.txt Dockerfile
docker-compose build
touch .built
stop :
docker-compose stop
clean : stop
docker-compose rm
rm .built
test : .built
docker-compose run web ./run_tests.sh ${ARGS}
.PHONY : run build clean stop test
- 45. Good ol’ Makefile
run : build
docker-compose up -d
build : .built
.built : requirements.txt Dockerfile
docker-compose build
touch .built
- 48. Ups… something went wrong.
Building image failed.
- it stops at layer that failed
- starts from the last correct layer (cache)
- 49. 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
- 51. 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