Full App Lifecycle with Compose
- Live The Dream!
Single set of Compose files for:
- Local
docker-compose up
development environment - Remote
docker-compose up
CI environment - Remote
docker stack deploy
production environment
- Local
Note:
docker-compose -f a.yml -f b.yml config
mostly works- Currently there is a bug with secrets
Note: Compose
extends:
doesn't work yet in Stacks
Files
~> ls -l
total 10
-rw-r--r-- 1 Stefan 197121 614 Sep 29 22:37 docker-compose.override.yml
-rw-r--r-- 1 Stefan 197121 589 Sep 29 22:37 docker-compose.prod.yml
-rw-r--r-- 1 Stefan 197121 357 Sep 29 22:37 docker-compose.test.yml
-rw-r--r-- 1 Stefan 197121 126 Sep 29 22:37 docker-compose.yml
-rw-r--r-- 1 Stefan 197121 314 Sep 29 22:37 Dockerfile
-rw-r--r-- 1 Stefan 197121 10 Sep 29 22:37 psql-fake-password.txt
drwxr-xr-x 1 Stefan 197121 0 Sep 29 22:37 sample-data/
docker-compose.override.yml
version: '3.1'
services:
drupal:
build: .
ports:
- "8080:80"
volumes:
- drupal-modules:/var/www/html/modules
- drupal-profiles:/var/www/html/profiles
- drupal-sites:/var/www/html/sites
- ./themes:/var/www/html/themes
postgres:
environment:
- POSTGRES_PASSWORD_FILE=/run/secrets/psql-pw
secrets:
- psql-pw
volumes:
- drupal-data:/var/lib/postgresql/data
volumes:
drupal-data:
drupal-modules:
drupal-profiles:
drupal-sites:
drupal-themes:
secrets:
psql-pw:
file: psql-fake-password.txt
docker-compose.prod.yml
version: '3.1'
services:
drupal:
ports:
- "80:80"
volumes:
- drupal-modules:/var/www/html/modules
- drupal-profiles:/var/www/html/profiles
- drupal-sites:/var/www/html/sites
- drupal-themes:/var/www/html/themes
postgres:
environment:
- POSTGRES_PASSWORD_FILE=/run/secrets/psql-pw
secrets:
- psql-pw
volumes:
- drupal-data:/var/lib/postgresql/data
volumes:
drupal-data:
drupal-modules:
drupal-profiles:
drupal-sites:
drupal-themes:
secrets:
psql-pw:
external: true
docker-compose.test.yml
version: '3.1'
services:
drupal:
image: bretfisher/custom-drupal
build: .
ports:
- "80:80"
postgres:
environment:
- POSTGRES_PASSWORD_FILE=/run/secrets/psql-pw
secrets:
- psql-pw
volumes:
- ./sample-data:/var/lib/postgresql/data
secrets:
psql-pw:
file: psql-fake-password.txt
docker-compose.yml
version: '3.1'
services:
drupal:
image: bretfisher/custom-drupal:latest
postgres:
image: postgres:9.6
Dockerfile
FROM drupal:8.2
RUN apt-get update && apt-get install -y git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /var/www/html/themes
RUN git clone --branch 8.x-3.x --single-branch --depth 1 https://git.drupal.org/project/bootstrap.git \
&& chown -R www-data:www-data bootstrap
WORKDIR /var/www/html
psql-fake-password.txt
mypasswd
- Folder sample-data has postgresql database sample data
Output
Local Composer
# Create everything
~> docker-compose up
Creating network "swarmstack3_default" with the default driver
Creating volume "swarmstack3_drupal-modules" with default driver
Creating volume "swarmstack3_drupal-sites" with default driver
Creating volume "swarmstack3_drupal-profiles" with default driver
Creating volume "swarmstack3_drupal-data" with default driver
Creating volume "swarmstack3_drupal-themes" with default driver
Building drupal
~~ omitted ~~
Creating swarmstack3_postgres_1 ...
Creating swarmstack3_drupal_1 ...
Creating swarmstack3_postgres_1
Creating swarmstack3_drupal_1 ... done
# Check if all is online
~> docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------
swarmstack3_drupal_1 docker-php-entrypoint apac ... Up 0.0.0.0:8080->80/tcp
swarmstack3_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp
~> docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1baea558c63 bretfisher/custom-drupal:latest "docker-php-entryp..." 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp swarmstack3_drupal_1
474b3516bcc4 postgres:9.6 "docker-entrypoint..." 2 minutes ago Up 2 minutes 5432/tcp swarmstack3_postgres_1
1c2b00adf213 postgres "docker-entrypoint..." 33 minutes ago Up 33 minutes 5432/tcp secretssample2_psql_1
~> docker network ls
NETWORK ID NAME DRIVER SCOPE
53c9e693ea8d bridge bridge local
6d80fdf5931f docker_gwbridge bridge local
7e049ea0340c host host local
8375866ba0bb none null local
ec6364e82569 secretssample2_default bridge local
6cda6d5d83fa swarmstack3_default bridge local
~> docker volume ls
DRIVER VOLUME NAME
local 20b0bc2b3559c84a713ed4683f2738c20326d602728000e88b836b7d9389cf9f
local swarmstack3_drupal-data
local swarmstack3_drupal-modules
local swarmstack3_drupal-profiles
local swarmstack3_drupal-sites
local swarmstack3_drupal-themes
# Everything working so let's bring it back down
~> docker-compose down
Stopping swarmstack3_drupal_1 ...
Stopping swarmstack3_postgres_1 ...
postgres_1 | LOG: received smart shutdown request
postgres_1 | LOG: autovacuum launcher shutting down
postgres_1 | LOG: shutting down
drupal_1 | [Wed Oct 04 17:41:47.170595 2017] [mpm_prefork:notice] [pid 1] AH00169: caught SIGTERM, shutting down
Stopping swarmstack3_drupal_1 ... done
swarmstack3_drupal_1 exited with code 0
Stopping swarmstack3_postgres_1 ... done
Removing swarmstack3_drupal_1 ... done
Removing swarmstack3_postgres_1 ... done
Removing network swarmstack3_default
Remote Compose (CI Testing)
~> docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d
Creating network "swarmstack3_default" with the default driver
Creating swarmstack3_postgres_1 ...
Creating swarmstack3_drupal_1 ...
Creating swarmstack3_drupal_1
Creating swarmstack3_drupal_1 ... done
- In testing environment we don't have any binded mounts
~> docker inspect swarmstack3_drupal_1
...
"Volumes": null,
...
~> docker-compose down
Stopping swarmstack3_drupal_1 ... done
Removing swarmstack3_drupal_1 ... done
Removing swarmstack3_postgres_1 ... done
Removing network swarmstack3_default
Production Config
- When we have split config into multiple files we can generate prod config like:
~> docker-compose -f docker-compose.yml -f docker-compose.prod.yml config
secrets:
psql-pw:
external: true
services:
drupal:
image: bretfisher/custom-drupal:latest
ports:
- 80:80/tcp
volumes:
- drupal-modules:/var/www/html/modules:rw
- drupal-profiles:/var/www/html/profiles:rw
- drupal-sites:/var/www/html/sites:rw
- drupal-themes:/var/www/html/themes:rw
postgres:
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/psql-pw
image: postgres:9.6
secrets:
- source: psql-pw
volumes:
- drupal-data:/var/lib/postgresql/data:rw
version: '3.1'
volumes:
drupal-data: {}
drupal-modules: {}
drupal-profiles: {}
drupal-sites: {}
drupal-themes: {}
~> docker-compose -f docker-compose.yml -f docker-compose.prod.yml config > output.yml