Docker Compose

Docker Compose

👉What is Docker Compose? What is Docker Compose used for? What is difference between docker and docker compose? Where to download docker compose? What all are the process used? How compose file looks like? What are docker compose version? Docker compose with version

What is Docker Compose?

Docker compose is a tool for running multi-container applications on docker defined using the compose file format. A compose file is used to define how one or more containers that make up your application are configured. Once you have a compose file you can create and start your application with a single command .

docker compose up

What is Docker Compose used for?

Docker Compose is a tool that helps you define and share multi-container applications. With Compose, you can create a YAML file to define the services and with a single command, you can spin everything up or tear it all down.

What is difference between docker and docker compose?

The key difference between docker run versus docker-compose is that docker run is entirely command line based, while docker-compose reads configuration data from a YAML file

Where to download docker compose?

For Linux, you can download docker compose binaries from the release page on the repository

  1. Install compose on Linux

  2. Install using repository

sudo yum update
sudo yum install docker-compose-plugin
  1. Plugin has been downloaded to check run below command to verify version.
docker compose version
  1. It will show docker compose version vN.N.N

  2. Create a file docker-compose.yml

  3. vi in visual editor in docker-compose.yml

  4. Navigate /root/compose-application

  5. Run command as below to start.

docker compose up

Great, you have successfully ran the compose now.

What all are the process used?

There is a three-step process:

  1. Define your app's environment with a docker file so it can be reproduced anywhere.

  2. Define the services that make up your app in compose.yaml so they can be run together in an isolated environment.

  3. Lastly, run docker compose up and compose will start and run your entire app.

How compose file looks like?

docker-compose.yml

services:
    web:
        image:"Shounak/simple-webapp
    database:
        image:"mongodb"
    orchestration:
        image:"ansible"
💡
docker-compose up is applicable to run on single docker host

What are docker compose version?

There are two different implementations of the compose tool, one written in python (docker-compose with a hyphen) and one written in Go and distributed as a docker extension (docker compose with a space)

docker-compose --version
docker compose version v2.17.2
versionSupportsPython ComposePlugin Compose
1absent Pre-Docker network
22, through 2.4 single-host DockerYY
33, through 3.8 Docker SwarmYY

version 2 generally directly mirrors docker run options.

version 3 has some options that are compatible with Swarm but are ignored if you aren't using it. which means the python version of compose will reject the file

Docker compose with version

version 1

redis:
  image:  redis
db:
  image:  postgres:9.4
vote: 
  image:  hello-shounak
  ports:
      -  5000:80
  links:
      -  redis

version 2

services:
  redis:
    image:  redis
  db:
    image:  postgres:9.4
  vote:
    image:  hello-shounak
    ports:
      -  5000:80
    depends_on:
      -  redis

version 3

services:
  redis:
    image:  redis
  db:
    image:  postgres:9.4
  vote:
    image:  hello-shounak
    ports:
      -  5000:80

🥳That's great if you have make till here you have covered basic of docker compose.

If you liked what you read, do follow and any feedback for further improvement will be highly appreciated!

Thank you and Happy Learning!👏