DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 46

Application Deployment

I successfully deployed a containerized application stack on App Server 3. The deployment utilized Docker Compose to orchestrate two services: a web server and a database. This article outlines the process, including the necessary steps, troubleshooting, and final validation.

Step 1: Creating the Docker Compose File

The first step was to create a docker-compose.yml file to define the services, images, ports, and volumes for the application stack. The file was created at /opt/devops/docker-compose.yml with the following configuration:

version: '3.8'
services:
  web:
    image: php:apache
    container_name: php_apache
    ports:
      - "5001:80"
    volumes:
      - "/var/www/html:/var/www/html"
  db:
    image: mariadb:latest
    container_name: mysql_apache
    ports:
      - "3306:3306"
    volumes:
      - "/var/lib/mysql:/var/lib/mysql"
    environment:
      MYSQL_DATABASE: database_apache
      MYSQL_USER: myuser
      MYSQL_PASSWORD: 'MyComplexPassword123!'
      MYSQL_ROOT_PASSWORD: 'AnotherStrongRootPassword!'
Enter fullscreen mode Exit fullscreen mode

This file specified two services: web and db. The web service uses the php:apache image, maps port 5001 on the host to port 80 in the container, and mounts the /var/www/html directory. The db service uses the mariadb:latest image, maps port 3306 on the host to port 3306 in the container, mounts the /var/lib/mysql directory, and sets up a new database and user via environment variables.

Step 2: Troubleshooting and Resolving Dependencies

Upon attempting to run the deployment with docker-compose up, the initial execution failed with a "command not found" error, indicating that Docker Compose was not installed.

To fix this, the following commands were executed to download and install the Docker Compose binary:

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

After installation, running docker-compose --version resulted in a new error: libcrypt.so.1: cannot open shared object file. This issue was resolved by installing the libxcrypt-compat package, which provides the missing library.

sudo yum install -y libxcrypt-compat
Enter fullscreen mode Exit fullscreen mode

A subsequent attempt to run docker-compose up resulted in a PermissionError, as the user banner did not have permissions to access the Docker daemon socket. This was fixed by adding the user to the docker group.

sudo usermod -aG docker banner
newgrp docker
Enter fullscreen mode Exit fullscreen mode

These steps resolved all installation and permission issues, preparing the environment for a successful deployment.

Step 3: Deployment and Validation

With all prerequisites met, the docker-compose up command was executed from the /opt/devops directory. The command successfully pulled the required images and started the containers for both services.

The logs confirmed that the MariaDB database was initialized and started, and the Apache web server was also running and ready to serve content.

Finally, the application's accessibility was validated using the curl command from a different host, targeting the stapp03 server on the mapped port 5001.

curl stapp03.stratos.xfusioncorp.com:5001/
Enter fullscreen mode Exit fullscreen mode

The output of the curl command was the HTML content of the default web page, confirming that the application was fully deployed and accessible as required.

<html>
    <head>
        <title>Welcome to xFusionCorp Industries!</title>
    </head>
    <body>
        Welcome to xFusionCorp Industries!
    </body>
</html>
Enter fullscreen mode Exit fullscreen mode

The successful response concluded the task, practicing the ability to troubleshoot and deploy a containerized application stack using Docker Compose.

Top comments (0)