Docker Compose For PHP Development
Mohamad Mahmood
1 min read
[1] Prep docker-compose.yml
version: '3.7'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80" # Expose port 80 inside the container to port 8080 on the host machine
volumes:
- ./src:/var/www/html # Mount the src directory to the web server's document root
networks:
- app_network
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: mydatabase
MYSQL_USER: user
MYSQL_PASSWORD: password
volumes:
- db_data:/var/lib/mysql # Persist database data between container restarts
networks:
- app_network
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- "8081:80" # Expose phpMyAdmin on port 8081
networks:
- app_network
networks:
app_network:
driver: bridge
volumes:
db_data:
[2] Start container
docker-compose up --build
0
Subscribe to my newsletter
Read articles from Mohamad Mahmood directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Mohamad Mahmood
Mohamad Mahmood
Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He studies at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).