Here is an example docker-compose.yml file that sets up a PHP web application, a MySQL database, and phpMyAdmin for managing the database
version: '3'
services:
web:
build: .
ports:
- 8080:80
volumes:
- .:/var/www/html
depends_on:
- db
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: db_name
MYSQL_USER: user
MYSQL_PASSWORD: password
volumes:
- db_data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8081:80
environment:
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: password
volumes:
db_data:
This file defines three services: web, db, and phpmyadmin.
The web service is based on a custom image that is built from the Dockerfile in the current directory. It exposes port 80 on the container as port 8080 on the host machine and mounts the current directory as a volume at /var/www/html in the container. The web service depends on the db service, so it will not start until the db service is running.
The db service is based on the official MySQL image and sets several environment variables to configure the root password, the name of the database, and the credentials for a user. It also creates a volume at /var/lib/mysql to persist the database data.
The phpmyadmin service is based on the official PHPMyAdmin image and exposes port 80 on the container as port 8081 on the host machine. It sets environment variables to specify the hostname of the MySQL server and the credentials to use to log in.
The volumes section at the bottom of the file defines a named volume called db_data that is used by the db service to persist the database data.
This is just one example of how you can set up a PHP, MySQL, and phpMyAdmin stack with Docker Compose. There are many other configurations and options that you can use depending on your specific needs.