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:
- On
App Server 1
inStratos Datacenter
create a docker compose file/opt/finance/docker-compose.yml
(should be named exactly)/ - The compose should deploy two services (web and DB), and each service should deploy a container as per details below:
- For Web Services:
a. Container name must bephp_apache
.
b. Use imagephp
with anyapache
tag. Check here for more details.
c. Mapphp_apache
container's port80
with host port5001
d. Mapphp_apache
container's/var/www/html
volume with host volume/var/www/html
. - For DB Services:
a. Container name must bemysql_apache
.
b. Use imagemariadb
with any tag (preferablylatest
). Check here for more details.
c. Mapmysql_apache
container's port3306
with host port3306
d. Mapmysql_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. - 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 |