To install WordPress with Docker Compose, you will need to have Docker and Docker Compose installed on your system.
Create a new directory for your WordPress project, and navigate to it in the terminal.
Create a docker-compose.yml file in the project directory and add the following configuration:
version: '3' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest ports: - "8080:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress volumes: db_data:
This configuration file specifies two Docker containers: one for the MySQL database, and one for WordPress. It also defines a volume for the MySQL data to ensure that it is persisted even if the container is stopped or removed.
Run the following command to start the containers:
docker-compose up -d
This will download the necessary images and start the containers in the background.
- Open a web browser and go to
http://localhost:8080to complete the WordPress installation. You will be prompted to enter your database details, which should be as follows:
- Database name:
- User name:
- Follow the on-screen instructions to complete the installation.
That’s it! You should now have WordPress installed and running in Docker using Docker Compose.