Skip to content

Instantly share code, notes, and snippets.

@stephenmelrose
Created September 25, 2015 15:26
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stephenmelrose/76da9c708691f090565d to your computer and use it in GitHub Desktop.
Save stephenmelrose/76da9c708691f090565d to your computer and use it in GitHub Desktop.
Docker folder structure

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,

  1. 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.
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment