Setting Up an Environment with Docker Compose

1 hour
  • 2 Learning Objectives

About this Hands-on Lab

In this Live Environment, you will be creating a development environment using PHP and MySQL for a project you are working on. Because the environment is a bit sophisticated, you’ve decided that it would be easier to build it out using Docker-Compose. Create a Docker-Compose file that sets up a db and webapp container. Use volumes so that your database and PHP files will be persistent.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Docker-Compose File
Run the Containers

Additional Resources

  1. In your root directory create your docker-compose.yml file:

    • Make sure you are using version 3.3.
    • The file will have two services: db and webapp.
    • The db will use mysql:5.7 for the image.
    • Create a volume called db_data that maps to /var/lib/mysql on the container.
    • Use restart: always to make sure the container always starts up.
    • Create the following environmental variables:
      • MYSQL_ROOT_PASSWORD: R00tP4ssw0rd
      • MYSQL_DATABASE: app_name
      • MYSQL_USER: db_user
      • MYSQL_PASSWORD: 4pp_n4meP4sswrd0!
    • The webapp will be using php:7.0-apache for the image.
  2. Create two logs:

    • Data volume app_data that maps to /var/www/html.
    • Volume for logs called app_logs that maps to /var/logs/apache2.
    • Link the db containers, webapp should always restart.
    • Finally, webapp should link to db.
  3. Once your docker-compose.yml is complete, bring the containers up and make sure they are detached.

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?