Sunday, August 2, 2020

Docker Compose

Description: Here I have explained, what is docker compose and how to use it

What is Docker Composer: Docker Composer is use to run multiple container as single service. If you wan to run application and database using single file you can achieve by using single file. 

How to install and run docker composer:

  • Download and install docker composer using below command
# curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# docker-compose --version
docker-compose version 1.21.2, build a133471


  • I have create docker-compose.yml file for word press and mysql database as follow

version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

  • Now run docker-compose to run yml file 
# docker-compose up 
  • Once process will completed you will get output 

No comments:

Post a Comment