Understanding DevOps Tool – Docker Compose
0 / 56
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 –
dnf config-manager —add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce
systemctl enable --now docker
Installing Docker Compose –
# curl -L https://github.com/docker/compose/releases/download/v2.3.4/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
# chmod 755 /usr/local/bin/docker-compose
# docker-compose --version
Install multiple containers (nginx & mysql) using docker compose –
# cat docker-compose.yml
Use docker-compose up command to start building the containers for mariadb and mysql
# docker-compose up -d
Use docker-compose ps to list containers
# docker-compose ps
Get web page of nginx-web containers
# curl localhost:8080
Check mysql connection to maraidb-db container
# mysql -h 127.0.0.1 -u pwadmin -p -e "show databases;"
# mysql -h 127.0.0.1 -u root -p -e "show variables like 'hostname';"
Check logs of containers –
# docker-compose logs | tail
Stop the containers –
# docker-compose stop
To remove containers –
# 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