0% found this document useful (0 votes)
13 views6 pages

What Is Docker Compose

Docker Compose allows running multiple containers as a single service. It defines and runs multi-container Docker applications. The document discusses Docker Compose and provides an example of using Docker Compose to launch Nginx and Mysql containers from a docker-compose.yml file.

Uploaded by

Ananth M.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

What Is Docker Compose

Docker Compose allows running multiple containers as a single service. It defines and runs multi-container Docker applications. The document discusses Docker Compose and provides an example of using Docker Compose to launch Nginx and Mysql containers from a docker-compose.yml file.

Uploaded by

Ananth M.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

What is Dockers Compose:

To understand Docker Compose, let’s look at Myntra as an example.


Myntra is a fashion e-commerce website similar to Amazon. You visit the
Myntra website through your web browser and go through several
activities, like logging in to your account, browsing a catalog, checking
out, and so on. Behind each of these activities or services are different
products, such as an account database, product database, cart
database, and others that run behind the scenes.

Each of these can be considered a microservice. The more


microservices you build into your environment, the more valuable it is to
have each of these services in their containers. But as a developer, you
should be able to jump from one container to another. This is where you
can relate this example to Docker, where Docker Compose can connect
different containers as a single service.
Docker Compose is used for running multiple containers as a single
service. Each of the containers here run in isolation but can interact with
each other when required. Docker Compose files are very easy to write
in a scripting language called YAML, which is an XML-based language
that stands for Yet Another Markup Language. Another great thing about
Docker Compose is that users can activate all the services (containers)
using a single command.

Benefits of Docker Compose

 Single host deployment - This means you can run everything on a single piece of
hardware

 Quick and easy configuration - Due to YAML scripts

 High productivity - Docker Compose reduces the time it takes to perform tasks

 Security - All the containers are isolated from each other, reducing the threat landscape

Now, you might be thinking that Docker Compose is quite similar to Docker Swarm,
but that’s not the case. Here are some of the differences between Docker Compose
and Docker Swarm:
Basic Commands in Docker Compose

 Start all services: Docker Compose up

 Stop all services: Docker Compose down

 Install Docker Compose using pip: pip install -U Docker-compose

 Check the version of Docker Compose: Docker-compose-v

 Run Docker Compose file: Docker-compose up -d

 List the entire process: Docker ps

 Scale a service - Docker Compose up -d -scale

 Use YAML files to configure application services - Docker Compose.yml


Lab #1: Create first docker compose file with
ngnix and mysql
In this lab we are going to bringup a nginx and mysql
containers using docker-compose.

Pre-requisite:

Tested Infrastructure
Platform Number of Instance Read

Play with Docker 1 5 min

Pre-requisite
 Create an account with DockerHub
 Open PWD Platform on your browser
 Click on Add New Instance on the left side of the screen
to bring up Alpine OS instance on the right side
Setup environment:
$ mkdir Myapp
$ cd Myapp
Now lets create passowrd file for our DB:
$ openssl rand -base64 32 > db_password.txt
$ openssl rand -base64 32 > db_root_password.txt
Create a docker-compose.yml file:
version: '3.1'
services:
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
- "443:443"
#Mysql DB
db:
image: mysql:5.7
container_name: Mysqldb
restart: unless-stopped
volumes:
- db_data:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_root_password
- db_password
secrets:
db_password:
file: db_password.txt
db_root_password:
file: db_root_password.txt

volumes:
db_data:
Create the compose container:
$ sudo docker-compose up
$ sudo docker-compose up -d
SSH into the instance and check the app
List out the compose services:
$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------
--------
Mysqldb docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp,
33060/tcp
webserver nginx -g daemon off; Up 0.0.0.0:443->443/tcp,
0.0.0.0:80->80/tcp

Verify the nginx is running:


$ curl http://localhost

Verify the Mysql db:


$ docker exec -it Mysqldb mysql -u root -p

Enter the root password which is in db_root_password.txt

You might also like