Build Services with Docker Compose

1.5 hours
  • 2 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

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

Additional Resources

In this hands-on lab, we will create a Ghost Blog service using Docker Compose.

  1. Log in to the live environment and sudo to root.
  2. Create a Docker Compose file in the root directory of your live environment. You will create two services: a Ghost Blog service and a MySQL service.
  3. Set the Compose version to 3.
  4. Create your first service called ghost.
  5. Use the ghost:1-alpine image.
  6. Call the container ghost-blog.
  7. You will use five environment variables:
    • Set database__client to mysql.
    • Set database__connection__host to mysql.
    • Set database__connection__user to root.
    • Set database__connection__password to P4sSw0rd0!
    • Set database__connection__database to ghost.
  8. Create a volume called ghost-volume and map it to /var/lib/ghost.
  9. Map port 80 on the host to port 2368 on the container.
  10. The ghost_blog container will be dependent on the mysql container.
  11. Make sure that the container always restarts.
  12. Create a second service called mysql.
  13. Use the mysql:5.7 image.
  14. Name the container ghost-db.
  15. You will add the following environment variable:
    • Set MYSQL_ROOT_PASSWORD to P4sSw0rd0!
  16. Create a volume called mysql-volume and map it to /var/lib/mysql.
  17. Make sure that the container always restarts.
  18. Make sure that the two volumes are called ghost-volume and mysql-volume.
  19. Execute a compose up and make sure to use the detached flag.
  20. Verify that your app is up and running.
What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?