118 lines
3.3 KiB
Markdown
118 lines
3.3 KiB
Markdown
# WordPress with MySQL Docker Application
|
|
|
|
This application deploys WordPress with MySQL as the database backend using Docker containers. The setup includes persistent storage for both the WordPress files and the MySQL database.
|
|
|
|
## Prerequisites
|
|
|
|
To run this application, you need:
|
|
|
|
- Docker Engine (version 20.10.0 or newer)
|
|
- Bash shell environment
|
|
- 1GB+ of free RAM
|
|
- 1GB+ of free disk space
|
|
- Internet connection to pull Docker images
|
|
|
|
## What the Application Does
|
|
|
|
This application sets up:
|
|
|
|
1. A WordPress instance that serves as a content management system
|
|
2. A MySQL database that stores WordPress data
|
|
3. Persistent volumes to maintain data between restarts
|
|
4. A dedicated network for secure inter-container communication
|
|
|
|
## Virtual Networks
|
|
|
|
- `wordpress_network`: A bridge network for communication between the WordPress and MySQL containers. This network allows the containers to reference each other by container name instead of IP addresses.
|
|
|
|
## Named Volumes
|
|
|
|
- `wordpress_data`: Stores WordPress files, themes, plugins, and uploads
|
|
- `db_data`: Stores MySQL database files
|
|
|
|
These volumes ensure data persistence across container restarts and application updates.
|
|
|
|
## Container Configuration
|
|
|
|
### MySQL Container
|
|
|
|
- Image: `mysql:5.7`
|
|
- Container name: `db`
|
|
- Environment variables:
|
|
- `MYSQL_ROOT_PASSWORD`: Root password for MySQL
|
|
- `MYSQL_PASSWORD`: Database password for the WordPress user
|
|
- `MYSQL_USER`: Database user for WordPress (jawad1)
|
|
- `MYSQL_DATABASE`: Database name for WordPress (cloud_database)
|
|
- Volume mounted: `db_data:/var/lib/mysql`
|
|
- Network: `wordpress_network`
|
|
- Restart policy: `unless-stopped` (automatically restarts if the container fails)
|
|
|
|
### WordPress Container
|
|
|
|
- Image: `wordpress:latest`
|
|
- Container name: `wordpress_app`
|
|
- Environment variables:
|
|
- `WORDPRESS_DB_HOST`: Database hostname (db)
|
|
- `WORDPRESS_DB_USER`: Database username (jawad1)
|
|
- `WORDPRESS_DB_PASSWORD`: Database password (jawad@password123)
|
|
- `WORDPRESS_DB_NAME`: Database name (cloud_database)
|
|
- `WORDPRESS_CONFIG_EXTRA`: Additional WordPress configuration
|
|
- Port mapping: `8080:80` (exposes WordPress on port 8080)
|
|
- Volume mounted: `wordpress_data:/var/www/html`
|
|
- Network: `wordpress_network`
|
|
- Restart policy: `unless-stopped` (automatically restarts if the container fails)
|
|
|
|
## Usage Instructions
|
|
|
|
### Preparing the Application
|
|
|
|
Run the prepare script to download Docker images:
|
|
|
|
```bash
|
|
chmod +x prepare-app.sh
|
|
./prepare-app.sh
|
|
```
|
|
|
|
### Running the Application
|
|
|
|
Start the containers with:
|
|
|
|
```bash
|
|
chmod +x start-app.sh
|
|
./start-app.sh
|
|
```
|
|
|
|
After starting, WordPress will be available at http://localhost:8080
|
|
|
|
The first load may take some time as WordPress initializes the database and sets up the environment.
|
|
|
|
### Stopping the Application
|
|
|
|
Stop the running containers without removing data:
|
|
|
|
```bash
|
|
chmod +x stop-app.sh
|
|
./stop-app.sh
|
|
```
|
|
|
|
### Removing the Application
|
|
|
|
To completely remove the application, including all data:
|
|
|
|
```bash
|
|
chmod +x remove-app.sh
|
|
./remove-app.sh
|
|
```
|
|
|
|
**Warning:** This will delete all your WordPress data and MySQL databases!
|
|
|
|
## Accessing the Web Application
|
|
|
|
After starting the application, access WordPress through your web browser at:
|
|
|
|
```
|
|
http://localhost:8080
|
|
```
|
|
|
|
The first time you access this URL, you'll be guided through the WordPress setup process where you can create an admin account and configure your site.
|