Wednesday, September 19, 2018

docker compose

Docker Compose:

Benefits:
-Configure relationships between containers.
-Save our docker container run settings in easy-to-read file
-Create one-line developer environment startups

Features:

-Comprised of 2 separate but related things
  1. YAML formatted files that describes solution options for:
     -containers
     -networks
     -volumes
  2. A CLI tool docker-compose used for local dev/test automation with those YAML files.

docker-compose.yml:
-compose YAML format has it's own versions:1,2,2.1,3,3.1
-YAML file can be  used with docker-compose command for local docker automation or..
-With docker directly in production with Swarm(as of v1.13)
-docker-compose --help
- docker-compose.yml is deafult filename, but any can be used with docker-compose -f


Reference: https://docs.docker.com/compose/compose-file

Installation:
comes by deafult with docker for windows.
But for linux download separately, https://github.com/docker/compose

Docker compose is not ideal for production, useful for dev and test environments.

docker-compose up #setup volumes/networks and start all containers.
docker-compose down #stop all containers and remove cont/vol/net

If all our projects had a Dockerfile and docker-compose.yml then "new developer onboarding" would be:
- git clone github.com/some/software
- docker-compose up

In the below compose file, in the volumes section .ro means read-only volume.
Two containers are created with 2 images.
It uses service names as dns names to have communication between containers.


sample docker-compose.yml:
---------------------------

version:'3'

services:
 proxy:
   image: nginx:1.11 #this will use the latest version of 1.11.x
   ports:
     - '80:80' #expose 80 on host and sent to 80 in container
   volumes:
     - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
 web:
   image: httpd # this will use httpd:latest

-------------------
docker-compose up

to output log background use -d.
then pick logs using: docker-compose logs

most of commands are similar to dcoker container..

for other commands: use: docker compose --help



Let's create a drupal and postgres containers usings compose(Multi container service).




And add this at end to provide named volumes.






At the end, if we want to remove volumes also, type below command.

docker compose down -v 

 






No comments:

Post a Comment