DEV Community

Cover image for Run Multi-container apps with Docker  Compose
Chauntel Kellar
Chauntel Kellar

Posted on


Run Multi-container apps with Docker Compose

Containerization of apps is a fast-growing practice as many companies are embracing the cloud and DevOps concepts. Docker packages an application, libraries, and its dependencies in a virtual container that can run on any server. Being that most applications do not run on one single component (even dinosaur apps πŸ¦– have frontend and backend components), we need a way to define and manage multi-container apps.

In this tutorial I will utilize Docker compose to get a blog up and running that consists of a Ghost Blog service and a MYSQL service; both services will use volumes for persistent storage. This tutorial assumes you have working knowledge of Docker and a server with Docker and Docker compose installed.

docker compose services

docker compose services

What is Docker Compose?

Compose is a file format for describing distributed Docker apps, and it’s a tool for managing them.

What is Ghost?

Ghost is a free and open source blogging platform written in Javascript.

Let’s go! 🐳

Step 1 β€” Login to the server and become root

1. SSH into the server and become root

ssh <username>@PUBLIC_IP_ADDRESS

sudo su -

Step 2 β€” Create a Ghost Blog and MySQL service

2. Create a docker-compose.yml file in the root directory

vi docker-compose.yml

Add the following contents

version: '3'
    image: ghost:1-alpine
    container_name: ghost-blog
    restart: always
      - 80:2368
      database__client: mysql
      database__connection__host: mysql
      database__connection__user: root
      database__connection__password: P4sSw0rd0!
      database__connection__database: ghost
      - ghost-volume:/var/lib/ghost
      - mysql

    image: mysql:5.7
    container_name: ghost-db
    restart: always
      - mysql-volume:/var/lib/mysql

Enter fullscreen mode Exit fullscreen mode

Step 3 β€” Start up the Docker compose service and Bring up the Ghost Blog

3. docker-compose up -d

Congrats your blog is up and running! Validate via the public IP address of your Docker server.

ghost blog

ghost blog

Connect with me on Twitter @toutfinesse

Top comments (5)

danbmky profile image
Dan Bamikiya • Edited

Great post @chauntelkellar I love how its short and simple to follow!

I just want to add:
Step 4 β€” View Docker compose logs
docker-compose logs -f to stop viewing the logs Ctrl+C

Step 5 β€” Stop specific Docker service
docker-compose stop ghost-blog

Step 6 β€” Stop all Docker compose services
docker-compose stop

chauntelkellar profile image
Chauntel Kellar

Thanks @danbamikiya ! I agree with your additions.

danbmky profile image
Dan Bamikiya

Thanks @chauntelkellar ! Have a great day!

vishalraj82 profile image
Vishal Raj

Great. I have an extension for your post. Please see -

chauntelkellar profile image
Chauntel Kellar

Great post!

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.