Skip to main content

Build Services with Docker Compose

Hands-On Lab

 

Photo of Travis Thomsen

Travis Thomsen

Course Development Director in Content

Length

01:30:00

Difficulty

Intermediate

For the last six months, the Acme Anvil Corporation has been migrating some of their bare metal infrastructure to Docker containers. Your team wants to find an easier way to deploy applications that consist of multiple containers and has decided to use Docker Compose. You have been tasked with setting up an internal blog so the team can write technical articles. This blog will consist of two services: a Ghost Blog service and a MySQL service. Both services will use volumes for persistent storage.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Build Services with Docker Compose

Introduction

For the last six months, the Acme Anvil Corporation has been migrating some of their bare metal infrastructure to Docker containers. Your team wants to find an easier way to deploy applications that consist of multiple containers and has decided to use Docker Compose. You have been tasked with setting up an internal blog so the team can write technical articles. This blog will consist of two services: a Ghost Blog service and a MySQL service. Both services will use volumes for persistent storage.

Solution

Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

ssh cloud_user@PUBLIC_IP_ADDRESS

Become the root user:

sudo su -

Create a Ghost Blog and MySQL Service

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

    vi docker-compose.yml
  2. Add the following contents to it:

    version: '3'
    services:
      ghost:
        image: ghost:1-alpine
        container_name: ghost-blog
        restart: always
        ports:
          - 80:2368
        environment:
          database__client: mysql
          database__connection__host: mysql
          database__connection__user: root
          database__connection__password: P4sSw0rd0!
          database__connection__database: ghost
        volumes:
          - ghost-volume:/var/lib/ghost
        depends_on:
          - mysql
    
      mysql:
        image: mysql:5.7
        container_name: ghost-db
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: P4sSw0rd0!
        volumes:
          - mysql-volume:/var/lib/mysql
    
    volumes:
      ghost-volume:
      mysql-volume:

Bring Up the Ghost Blog Service

  1. Start up the Docker Compose service.

    docker-compose up -d

Conclusion

Congratulations, you've completed this hands-on lab!