Visit my latest wiki at wiki.pacroy.com
Comprised of 2 separate but related things
docker-compose
command for local docker automation or..docker
directly in production with Swarm (as of v1.13)docker-compose --help
docker-compose.yml
is default filename, but any can be used with docker-compose -f
version: '3.1' # if no version is specificed then v1 is assumed. Recommend v2 minimum
services: # containers. same as docker run
servicename: # a friendly name. this is also DNS name inside network
image: # Optional if you use build:
command: # Optional, replace the default CMD specified by the image
environment: # Optional, same as -e in docker run
volumes: # Optional, same as -v in docker run
servicename2:
volumes: # Optional, same as docker volume create
networks: # Optional, same as docker network create
This create a Jekyll service.
version: '2'
# same as
# docker run -p 80:4000 -v $(pwd):/site bretfisher/jekyll-serve
services:
jekyll:
image: bretfisher/jekyll-serve
volumes:
- .:/site
ports:
- '80:4000'
This creates a wordpress service.
version: '2'
services:
wordpress:
image: wordpress
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: example
WORDPRESS_DB_PASSWORD: examplePW
volumes:
- ./wordpress-data:/var/www/html
mysql:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: examplerootPW
MYSQL_DATABASE: wordpress
MYSQL_USER: example
MYSQL_PASSWORD: examplePW
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
docker-compose up
# setup volumes/networks and start all containersdocker-compose down
# stop all containers and remove cont/vol/netDockerfile
and docker-compose.yml
then “new developer onboarding” would be:
git clone github.com/some/software
docker-compose up
Clone https://github.com/BretFisher/udemy-docker-mastery/tree/master/compose-sample-2
docker-compose up
for running in the foreground
docker-compose up -d
for running in the background
docker-compose logs
to see the log
docker-compose ps
to see list of containers
docker-compose top
to see list of processes
docker-compose down
to stop and remove the service
drupal
image along with the postgres
imagePOSTGRES_PASSWORD
for postgreslocalhost
, but it’s service nameversion: '2'
services:
drupal:
image: drupal
ports:
- 8080: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:
image: postgres
environment:
- POSTGRES_PASSWORD=yourpasswd
volumes:
drupal-modules:
drupal-profiles:
drupal-sites:
drupal-themes: