Learning Docker Compose

What is YAML

YAML is a data serialization language that is often used for writing configuration files. These files have the extension .yml or .yaml.The file consists of key-value pairs and is case-sensitive.YAML is very similar to XML and JSON.

Docker compose

Docker compose uses YAML files , with which we can build and run together multiple containers.

example:

version: '3.9'

services:
  web:
    image: ubuntu
    ports:
      - "8000:8000"

the above YAML is same as running the following command :

docker run -d -p 8000:8000 --name web ubuntu

Running multiple containers

For example, we want to run 2 different containers having Mongodb and nginx simultaneously:

  • Write a YAML file

  • docker-compose config :will show if the YAML file has any error

  • docker-compose -f <yaml_file_name> up : Create and start containers

once you have run the above command all the containers mentioned will get created, You can check by running localHost_ip:27017 and localHost_ip:8001 inside your Chrome.

  • if you want to stop all the containers you can use,

    docker-compose -f <yaml_file_name> down.

  • if you want to check the logs of the container,

    docker logs container

Thank you for reading!!

~Sujata Kumari