I generally have Docker related stuff in a subfolder in my repo. In the example below, all the code is sat in the root, but you could equally put all the code in a subfolder as well.
<repo_folder>
code/
more_code/
docker/
bin/
setup.sh
nginx/
Dockerfile
some_config_file
php/
Dockerfile
some_config_file.ini
some_other_config_file.ini
start.sh
Each subfolder in Docker represents a custom image I will build. I generally run multiple containers and seperate things where possible. An example from a project,
- mysql
- redis
- rabbit-mq
- php-fpm
- nginx
A lot of people aren't a fan of this style, and instead do the "all-in-one" style. Personally having read up on Docker, I like to keep things seperate for 2 reasons,
- It better reflects the real world. MySQL never lives on the same box as your app, so having them in containers make them communicate over networking.
- From my research I did a while ago, a Docker container seemed better suited at doing 1 thing. They're not VMs. So I tried to keep them to 1 main process. This seperation does add complexity, but feels more natural IMO.
It's then a case of pulling/building each image, and starting them. I usually put all this in the setup.sh
to save repetition.