Thursday, June 24, 2021

Docker compose what is it

 Docker compose what is it


Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.


Using Compose is basically a three-step process:

  1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
  2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
  3. Run docker compose up and the Docker compose command starts and runs your entire app. You can alternatively run docker-compose up using the docker-compose binary.

A docker-compose.yml looks like this:


version: "3.9"  # optional since v1.27.0

services:

  web:

    build: .

    ports:

      - "5000:5000"

    volumes:

      - .:/code

      - logvolume01:/var/log

    links:

      - redis

  redis:

    image: redis

volumes:

  logvolume01: {}


Compose has commands for managing the whole lifecycle of the application:


  • Start, stop, and rebuild services
  • View the status of running services
  • Stream the log output of running services
  • Run a one-off command on a service


The features of Compose that make it effective are:


Multiple isolated environments on a single hos

Preserve volume data when containers are created

Only recreate containers that have changed

Variables and moving a composition between environments



  • on a dev host, to create multiple copies of a single environment, such as when you want to run a stable copy for each feature branch of a project
  • on a CI server, to keep builds from interfering with each other, you can set the project name to a unique build number
  • on a shared host or dev host, to prevent different projects, which may use the same service names, from interfering with each other



References:

https://docs.docker.com/compose/#multiple-isolated-environments-on-a-single-host

No comments:

Post a Comment