The Nautilus Application development team recently finished development of one of the apps that they want to deploy on a containerized platform. The Nautilus Application development and DevOps teams met to discuss some of the basic pre-requisites and requirements to complete the deployment. The team wants to test the deployment on one of the app servers before going live and set up a complete containerized stack using a docker compose fie. Below are the details of the task:

  1. On App Server 1 in Stratos Datacenter create a docker compose file /opt/finance/docker-compose.yml (should be named exactly)/
  2. The compose should deploy two services (web and DB), and each service should deploy a container as per details below:
  3. For Web Services:
    a. Container name must be php_apache.
    b. Use image php with any apache tag. Check here for more details.
    c. Map php_apache container's port 80 with host port 5001
    d. Map php_apache container's /var/www/html volume with host volume /var/www/html.
  4. For DB Services:
    a. Container name must be mysql_apache.
    b. Use image mariadb with any tag (preferably latest). Check here for more details.
    c. Map mysql_apache container's port 3306 with host port 3306
    d. Map mysql_apache container's /var/lib/mysql volume with host volume /var/lib/mysql.
    e. Set MYSQL_DATABASE=database_apache and use any custom user ( except root ) with some complex password for DB connections.
  5. After running docker-compose up you can access the app with curl command curl <server-ip or hostname>:5001/
ssh in as normal
cd /opt/finance
sudo vi docker-compose.yml

version: '3.8'

services:
  web:
    image: php:apache
    container_name: php_apache
    ports:
      - "5001:80"
    volumes:
      - /var/www/html:/var/www/html
    depends_on:
      - db

  db:
    image: mariadb:latest
    container_name: mysql_apache
    environment:
      MYSQL_DATABASE: database_apache
      MYSQL_USER: appuser
      MYSQL_PASSWORD: C0mpl3xP@ss!
      MYSQL_ROOT_PASSWORD: rootpass123
    ports:
      - "3306:3306"
    volumes:
      - /var/lib/mysql:/var/lib/mysql
esc
wq!

sudo docker compose up -d
[+] Running 25/25
 ✔ db Pulled 29.8s
 -- snipped --
 ✔ web Pulled 61.6s
-- snipped --
[+] Running 3/3
 ✔ Network finance_default  Created                                                         0.1s 
 ✔ Container mysql_apache   Started                                                        19.8s 
 ✔ Container php_apache     Started                                                        13.1s 

sudo docker ps
CONTAINER ID   IMAGE            COMMAND                  CREATED         STATUS         PORTS                    NAMES
37a280dc7d44   php:apache       "docker-php-entrypoi…"   3 minutes ago   Up 3 minutes   0.0.0.0:5001->80/tcp     php_apache
887f4f9aee00   mariadb:latest   "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes   0.0.0.0:3306->3306/tcp   mysql_apache

curl stapp01:5001
<html>
    <head>
        <title>Welcome to xFusionCorp Industries!</title>
    </head>

    <body>
        Welcome to xFusionCorp Industries!    </body>
Service Container Name Image Host ↔ Container Port Volume Mapping Environment Variables
web php_apache php:apache 5001:80 /var/www/html:/var/www/html
db mysql_apache mariadb:latest 3306:3306 /var/lib/mysql:/var/lib/mysql MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD, MYSQL_ROOT_PASSWORD