Understanding DevOps Tool – Docker Compose
0
/
125

Docker Compose Overview
Docker has made it easy to build up a secure sandboxed local development environment. However, if you wish to construct more than one container for your application, you must generate several Docker files. This adds to the workload of maintaining them and is also time-consuming.
Docker Compose solves this problem by enabling you to run several container apps at the same time using a YAML file. You may define the number of containers, their builds, and storage architectures, and then create, run, and configure all of them with a single set of instructions.
Docker Compose is ideal for development, testing, and staging environments, as well as continuous integration processes.
Docker Compose is a tool that allows you to operate numerous containers as a single service. For example, if you had an application that required NGNIX and Mariadb, you could build a single file that started both containers as a service, eliminating the need to start each one separately.
Install Docker –
1 | dnf config-manager —add-repo=https://download.docker.com/linux/centos/docker-ce.repo |
1 | dnf install -y docker-ce |
1 | systemctl enable --now docker |
Installing Docker Compose –
1 | # curl -L https://github.com/docker/compose/releases/download/v2.3.4/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose |
1 | # chmod 755 /usr/local/bin/docker-compose |
1 | # docker-compose --version |

Install docker compose
Install multiple containers (nginx & mysql) using docker compose –
# cat docker-compose.yml
version: ‘3’
services:
db:
image: mariadb
container_name: maria-db
environment:
MYSQL_ROOT_PASSWORD: pwadmin
MYSQL_USER: pwadmin
MYSQL_PASSWORD: pwadming
MYSQL_DATABASE: mydb1
ports:
– “3306:3306”
web:
image: nginx
container_name: nginx-web
ports:
– “8080:80”

Use docker-compose up command to start building the containers for mariadb and mysql
1 | # docker-compose up -d |

Docker compose up
Use docker-compose ps to list containers
1 | # docker-compose ps |
Get web page of nginx-web containers
1 | # curl localhost:8080 |

docker ps
Check mysql connection to maraidb-db container
1 | # mysql -h 127.0.0.1 -u pwadmin -p -e "show databases;" |
1 | # mysql -h 127.0.0.1 -u root -p -e "show variables like 'hostname';" |

Mysql Connection
Check logs of containers –
1 | # docker-compose logs | tail |

Docker compose logs
Stop the containers –
1 | # docker-compose stop |
To remove containers –
1 | # docker-compose rm |
? Going to remove maria-db, nginx-web Yes

I hope you now have the knowledge you need to learn more about installing docker-compose and perhaps you can utilize it in a project in the future. Follow us on facebook:- Facebook & Linkedin:- LinkedIn