Docker Compose¶
- Why: configure relationships between containes
- Why: save our docker container run settings in easy-to-read file
- Why: create one-liner developer environment startups
-
Comprised of 2 seperate but related things
-
YAML-formatted file that describes our solution options for:
- containers
- networks
- volumes
-
A CLI tool
docker-composeused for local dev/test automation with those YAML files
-
docker-compose.yml¶
- Compose YAML format has it's own versions: 1, 2, 2.1, 3, 3.1
- YAML file can be used with
docker-composecommand for local docker automation or... - With
dockerdirectly in production with Swarm (as of v1.13) docker-compose --helpdocker-compose.ymlis default filename, but any can be used withdocker-compose -f
docker-compose CLI¶
- CLI tool comes with Docker for WIndows/Mac, but separate download for Linux
- Not a production-grade tool but ideal for local development and test
-
Two most common commands are
docker-compose up- setup volumes/networks and start all containersdocker-compose down- stop all containers and remove cont/vol/net
-
If all your projects had a
Dockerfileanddocker-compose.ymlthen "new developer onboarding" would be:git clone github.com/some/softwaredocker-compose up
Use Compose to Build¶
- Compose can also build your custom images
- WIll build them with
docker-compose upif not found in cache - Also rebuild with
docker-compose build - Great for complex builds that have lots of vars or build args