Setup MySQL and phpMyAdmin using Docker Compose
Updated:
Docker Compose Configuration
Create a docker-compose.yml
file with the following content:
version: '3.8'
services: mysql: image: mysql:8.0 container_name: mysql restart: always environment: MYSQL_ROOT_PASSWORD: your_root_password # Replace with a strong password MYSQL_DATABASE: your_database_name # Replace with your database name MYSQL_USER: your_db_user # Replace with your database username MYSQL_PASSWORD: your_db_password # Replace with your database user password ports: - "3306:3306" # Expose the MySQL port to the host volumes: - mysql_data:/var/lib/mysql # Persist data across restarts networks: # Added network - mynetwork
phpmyadmin: image: phpmyadmin:latest container_name: phpmyadmin restart: always environment: PMA_HOST: mysql # Connect using the service name PMA_USER: PMA_PASSWORD: UPLOAD_LIMIT: 100M # Example: Increase upload limit (optional) MEMORY_LIMIT: 512M # Example: Increase memory limit (optional) depends_on: - mysql ports: - "8080:80" networks: # Added network - mynetwork
volumes: mysql_data:
networks: # Explicitly define the network mynetwork: driver: bridge
Steps to Run
-
Save the
docker-compose.yml
file in your project directory. -
Run the following commands:
docker-compose up -d
-
Access phpMyAdmin in your browser:
- URL: http://localhost:8080
- Username: root
- Password: rootpassword
Rebuild and restart the containers to apply any changes:
docker-compose down -vdocker-compose up -d