For practicing purpose of Docker basic knowledge I got for the last days, I decided to create a very very simple project using Mariadb, PHP Framework-X (the simple and fast micro framework for building reactive web applications with PHP) and vanilla PHP.
This project consists in having three different systems running on diffent Docker Containers and communicating each other, so:
- I created an image based on the official mariadb image.
- I created a REST API using Framework-X which queries Mariadb database.
- finally I created a website using vanilla PHP and Bootstrap which consumes the API for gettting data.
cd api
composer install
docker build -t dev-mysql-image -f api/db/Dockerfile .
docker build -t dev-php-api-image -f api/Dockerfile .
docker build -t dev-php-website -f website/Dockerfile .
On project root folder:
docker run -d -p 33336:3306 -v $(pwd)/api/db/data:/var/lib/mysql --rm --name dev-mysql-container dev-mysql-image
docker run -d -p 9001:8080 -v $(pwd)/api/data:/app --rm --name dev-php-api-container dev-php-api-image
docker run -d -p 9002:8080 -v $(pwd)/website/data:/www --rm --name dev-website-container dev-website-image
docker exec -i dev-mysql-container mysql -uroot -p12345678 < api/db/script/initialize_db.sql
Now you can open your browser and type http://127.0.0.1:9002 and see everything working well