DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Deploy an App on Docker Containers

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 2 in Stratos Datacenter create a docker compose file /opt/sysops/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:

For web service:

a. Container name must be php_host.

b. Use image php with any apache tag. Check here for more details.

c. Map php_host container's port 80 with host port 3000

d. Map php_host container's /var/www/html volume with host volume /var/www/html.

For DB service:

a. Container name must be mysql_host.

b. Use image mariadb with any tag (preferably latest). Check here for more details.

c. Map mysql_host container's port 3306 with host port 3306

d. Map mysql_host container's /var/lib/mysql volume with host volume /var/lib/mysql.

e. Set MYSQL_DATABASE=database_host and use any custom user ( except root ) with some complex password for DB connections.

  1. After running docker-compose up you can access the app with curl command curl <server-ip or hostname>:3000/

For more details check here.

Note: Once you click on FINISH button, all currently running/stopped containers will be destroyed and stack will be deployed again using your compose file.


Connect to App Server 2

ssh steve@stapp02
sudo -i
Enter fullscreen mode Exit fullscreen mode

Password for steve: Am3ric@


Create the Compose Directory

mkdir -p /opt/sysops
Enter fullscreen mode Exit fullscreen mode

Create the Docker Compose File

vi /opt/sysops/docker-compose.yml
Enter fullscreen mode Exit fullscreen mode

Add the following content:

version: "3.8"

services:
  web:
    image: php:8.2-apache
    container_name: php_host
    ports:
      - "3000:80"
    volumes:
      - /var/www/html:/var/www/html
    depends_on:
      - db

  db:
    image: mariadb:latest
    container_name: mysql_host
    ports:
      - "3306:3306"
    volumes:
      - /var/lib/mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: database_host
      MYSQL_USER: nautilus_user
      MYSQL_PASSWORD: S3cur3P@ssw0rd!
      MYSQL_ROOT_PASSWORD: R00tP@ssw0rd!
Enter fullscreen mode Exit fullscreen mode

Verify the Compose File

cat /opt/sysops/docker-compose.yml
Enter fullscreen mode Exit fullscreen mode

Output:

version: "3.8"

services:
  web:
    image: php:8.2-apache
    container_name: php_host
    ports:
      - "3000:80"
    volumes:
      - /var/www/html:/var/www/html
    depends_on:
      - db

  db:
    image: mariadb:latest
    container_name: mysql_host
    ports:
      - "3306:3306"
    volumes:
      - /var/lib/mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: database_host
      MYSQL_USER: nautilus_user
      MYSQL_PASSWORD: S3cur3P@ssw0rd!
      MYSQL_ROOT_PASSWORD: R00tP@ssw0rd!
Enter fullscreen mode Exit fullscreen mode

Validate the Compose Configuration

cd /opt/sysops
docker compose config
Enter fullscreen mode Exit fullscreen mode

Output:

WARN[0000] /opt/sysops/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
name: sysops
services:
  db:
    container_name: mysql_host
    environment:
      MYSQL_DATABASE: database_host
      MYSQL_PASSWORD: S3cur3P@ssw0rd!
      MYSQL_ROOT_PASSWORD: R00tP@ssw0rd!
      MYSQL_USER: nautilus_user
    image: mariadb:latest
    networks:
      default: null
    ports:
      - mode: ingress
        target: 3306
        published: "3306"
        protocol: tcp
    volumes:
      - type: bind
        source: /var/lib/mysql
        target: /var/lib/mysql
        bind: {}
  web:
    container_name: php_host
    depends_on:
      db:
        condition: service_started
        required: true
    image: php:8.2-apache
    networks:
      default: null
    ports:
      - mode: ingress
        target: 80
        published: "3000"
        protocol: tcp
    volumes:
      - type: bind
        source: /var/www/html
        target: /var/www/html
        bind: {}
networks:
  default:
    name: sysops_default
Enter fullscreen mode Exit fullscreen mode

The configuration validates successfully. The version attribute warning is informational only and does not affect the deployment.


Deploy the Stack

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Output:

WARN[0000] /opt/sysops/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] up 29/29
 ✔ Image mariadb:latest   Pulled                                                                                          11.5s
 ✔ Image php:8.2-apache   Pulled                                                                                          13.5s
 ✔ Network sysops_default Created                                                                                         0.1s
 ✔ Container mysql_host   Created                                                                                         0.1s
 ✔ Container php_host     Created                                                                                         0.1s
Enter fullscreen mode Exit fullscreen mode

Both images were pulled, the network was created, and both containers were started.


Verify the Containers Are Running

docker compose ps
Enter fullscreen mode Exit fullscreen mode

Output:

NAME         IMAGE            COMMAND                  SERVICE   CREATED         STATUS         PORTS
mysql_host   mariadb:latest   "docker-entrypoint.s…"   db        4 seconds ago   Up 2 seconds   0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp
php_host     php:8.2-apache   "docker-php-entrypoi…"   web       4 seconds ago   Up 2 seconds   0.0.0.0:3000->80/tcp, [::]:3000->80/tcp
Enter fullscreen mode Exit fullscreen mode

Both containers are running with the correct names and port mappings.


Test the Web Service

curl -I http://localhost:3000/
Enter fullscreen mode Exit fullscreen mode

Output:

HTTP/1.1 200 OK
Date: Thu, 29 Oct 2026 08:57:43 GMT
Server: Apache/2.4.69 (Debian)
X-Powered-By: PHP/8.2.35
Content-Type: text/html; charset=UTF-8
Enter fullscreen mode Exit fullscreen mode

The HTTP 200 OK response confirms the PHP/Apache container is accessible on host port 3000 and running PHP 8.2.35.


Complete Command Sequence

ssh steve@stapp02
sudo -i

mkdir -p /opt/sysops

cat > /opt/sysops/docker-compose.yml << 'EOF'
version: "3.8"

services:
  web:
    image: php:8.2-apache
    container_name: php_host
    ports:
      - "3000:80"
    volumes:
      - /var/www/html:/var/www/html
    depends_on:
      - db

  db:
    image: mariadb:latest
    container_name: mysql_host
    ports:
      - "3306:3306"
    volumes:
      - /var/lib/mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: database_host
      MYSQL_USER: nautilus_user
      MYSQL_PASSWORD: S3cur3P@ssw0rd!
      MYSQL_ROOT_PASSWORD: R00tP@ssw0rd!
EOF

cd /opt/sysops
docker compose config
docker compose up -d
docker compose ps
curl -I http://localhost:3000/
Enter fullscreen mode Exit fullscreen mode

Top comments (0)