Skip to content

Instantly share code, notes, and snippets.

@falmar
Created November 23, 2017 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falmar/0c0ef2981436debad3a35906ae07a15f to your computer and use it in GitHub Desktop.
Save falmar/0c0ef2981436debad3a35906ae07a15f to your computer and use it in GitHub Desktop.
Docker compose files: local + swarm stack
version: '3.4'
services:
mysql:
volumes:
- db:/var/lib/mysql
ports:
- 3306:3306
environment:
- MYSQL_PASSWORD=database_password
php:
user: '1000'
depends_on:
- mysql
volumes:
- ./:/usr/share/nginx/html
nginx:
ports:
- 8080:80
depends_on:
- php
volumes:
- ./:/usr/share/nginx/html
volumes:
db: {}
# Production deploy swarm stack CI/CD
# ... build images ...
# ... push images to [public/private] docker registry ...
# Generate full docker compose file + env variable substitution
# $ SHORT_COMMIT_ID=e92fea9 docker-compose -f docker-compose.yml -f docker-compose.prod.yml config > prod.yml
# $ cat prod.yml | ssh user@server sudo docker stack deploy -c - wordpress --prune --with-registry-auth
version: '3.4'
services:
mysql:
image: mysql:5.7
secrets:
- db_pwd
environment:
- MYSQL_PASSWORD_FILE=/run/secrets/db_pwd
volumes:
- /path-gluster-mount/mysql:/var/lib/mysql
deploy:
replicas: 1
update_config:
parallelism: 1
delay: 2s
order: start-first
monitor: 1s
failure_action: rollback
restart_policy:
condition: any
delay: 1s
max_attempts: 3
resources:
limits:
cpus: '0.10'
memory: 400M
reservations:
cpus: '0.05'
memory: 250M
php:
image: your/image:wp_php_${SHORT_COMMIT_ID}
secrets:
- source: wp_config
target: /usr/share/nginx/html/public/wp-config.php
volumes:
- /path-gluster-mount/wp-content/uploads:/usr/share/nginx/html/public/wp-content/uploads
- /path-gluster-mount/wp-content/upgrade:/usr/share/nginx/html/public/wp-content/upgrade
- /path-gluster-mount/wp-content/cache:/usr/share/nginx/html/public/wp-content/cache
- /path-gluster-mount/wp-content/blogs.dir:/usr/share/nginx/html/public/wp-content/blogs.dir
- /path-gluster-mount/wp-content/backups:/usr/share/nginx/html/public/wp-content/backups
deploy:
replicas: 1
update_config:
parallelism: 1
delay: 2s
order: start-first
monitor: 1s
failure_action: rollback
restart_policy:
condition: any
delay: 1s
max_attempts: 3
resources:
limits:
cpus: '0.10'
memory: 200M
reservations:
cpus: '0.05'
memory: 80M
nginx:
image: your/image:wp_nginx_${SHORT_COMMIT_ID}
volumes:
- /path-gluster-mount/wp-content/uploads:/usr/share/nginx/html/public/wp-content/uploads
- /path-gluster-mount/wp-content/upgrade:/usr/share/nginx/html/public/wp-content/upgrade
- /path-gluster-mount/wp-content/cache:/usr/share/nginx/html/public/wp-content/cache
- /path-gluster-mount/wp-content/blogs.dir:/usr/share/nginx/html/public/wp-content/blogs.dir
- /path-gluster-mount/wp-content/backups:/usr/share/nginx/html/public/wp-content/backups
deploy:
replicas: 1
update_config:
parallelism: 1
delay: 2s
order: start-first
monitor: 1s
failure_action: rollback
restart_policy:
condition: any
delay: 1s
max_attempts: 3
resources:
limits:
cpus: '0.10'
memory: 200M
reservations:
cpus: '0.05'
memory: 50M
# create your secrets
secrets:
db_pwd:
external: true
wp_config:
external: true
version: '3.4'
services:
mysql:
image: mysql:5.7
environment:
- MYSQL_RANDOM_ROOT_PASSWORD=1
- MYSQL_DATABASE=community
- MYSQL_USER=community
networks:
- net
php:
# https://github.com/falmar/docker-repos/tree/master/php/7.1
image: falmar/php:7.1
networks:
- net
nginx:
# https://github.com/falmar/docker-repos/tree/master/nginx/laravel
image: falmar/nginx:laravel
networks:
- net
networks:
net: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment