Docker Compose allows developers to define and run multi-container Docker applications. It helps coordinate multiple containers to work together by defining them in a single compose file. This avoids the complexity of using raw Docker commands. Compose files define services, their images, dependencies, volumes, ports, etc. Compose then automates setting up and running the entire application with a single command. This provides an isolated development environment approximating production. It enables features like continuous integration testing against real services rather than mocks. Overall, Docker Compose improves the developer experience by simplifying and streamlining local development and testing of multi-container applications on Docker.
3. Things no developer/architect/CTO likes in during
development
● recognizing wrong choices when it is too late
● mantaining different development
environments
● targeting that VERY specific version
of something
● spending hours on configuring the
dev environment
4. Fighting back
● Create approximation of systems and
architectures
● Isolate yourself from the host
● Infrastructure as code
● Automate like there is no to tomorrow
5. Isolated work environments and teamwork
● If you are working on a backend application
front end people can avoid writing tons of
mocks or use a shared staging environment
● In case of error the application state can be
debugged easily
6. Vagrant
Vagrant made this approach popular by
virtualizing machines on real
hypervisors,
● Very accurate replicas
● Performance issues when running
complex architectures
● Provisioning looks intense
7. Docker
● You don’t have virtual machines
● The OS kernel is shared in virtualized
environment called containers.
● The virtualized processes are essentially native, do
not require the overhead of virtual machines and still
provide a high level of isolation from the host OS
9. Some docker terms
● Image: a readonly template for creating
containers - they are defined with simple files
called Dockerfiles
● Container: A Docker container is a runnable
instance of a Docker image
10. Some more docker terms
● Registry: a repository of docker images
● Volumes: (aka data volumes): folders that
bypass docker’s union filesystem. We can use
them to map folders from the host machine to
the container
12. Example Dockerfile
A dockerfile is like a recipe to build an image
Each line corresponds to a new layer in the image.
FROM node:7
RUN npm install -g knex nodemon mocha istanbul node-gyp snyk jsdoc
WORKDIR /src
13. Docker CLI is semi hard
Docker CLI can have quite a lot of options
Setting up a serious multi container environment
can be very hard
docker run -d -v ~/nginxlogs:/var/log/nginx -p 5000:80 -i nginx --
entrypoint /bin/bash example/nginx
15. Enter docker-compose
Docker compose helps by defining and
coordinating multiple containers.
With Compose, you define a multi-container
application in a .yml single file, then spin your
application up in a single command which does
everything that needs to be done to get it running.
17. Key points
● We are not provisioning a set of machines, we
are defining a set of services
● Then isolating them in containers
● And then choosing how they interact
18. Cool things
Services and middlewares are super easy to install: as they can be installed right
from the docker registry, the version we want, with the image
Basic configuration is achieved with env vars, advanced configuration by mapping
volumes
19. Approximating the production environment
● a good approximation of
the production
environment is the key for
true happiness
● integration tests can be run
on local machines for cheap
- spot architectural issues
very very early
20. Even more goodies
Continous integration is super easy to setup: at its
most basic form it can be reduced to something
like:
docker-compose run myservice npm
test
21. Testing in docker-compose
Allows you test against real services not mocks- all
tests can be integration tests.
No CI provider lock-in (as long docker compose is
supported)
Lightweight - you can spin up a lot services and
simulate complex architectures
22. Production?
Can be also used to setup a quick and dirty staging
environment.
Just use the -d flag
Docker swarm?
23. Issues and not so cool things
It’s all fun and games as long as you work on linux
● On mac and windows it used to run on a virtual
machine
● Now it’s better because it runs on hyper-V on
windows and xhyve on MAC (which is still a
virtualization)
24. Issues
On mac and windows installing and updating
docker has been more time consuming than
expected
The first docker-compose up run is always
quite painful
25. SSH keys
What if you need your ssh credentials inside your
container? I learned to hate:
● ssh passphrases
● windows permissions