This article briefly demonstrates how to use Docker-Compose to build a wordpress environment.
Create docker-compose file First, let’s create a new one file - named: wordpress-compose.yml, the content is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 version: "2.0" services: wpdb: image: mysql/mysql-server:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - wpdb image: wordpress:latest ports: - "8080:80" restart: always environment: WORDPRESS_DB_HOST: wpdb:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress
Then execute in the directory where the file is located:
1 docker-compose -f wordpress-compose.yml up -d
In Apple M1 Mainly because the official MySQL mirror of docker does not have an arm64 version, it is enough to switch to MySQL’s own mirror. The modified compose file is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 version: "2.0" services: wpdb: image: mysql/mysql-server:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - wpdb image: wordpress:latest ports: - "8080:80" restart: always environment: WORDPRESS_DB_HOST: wpdb:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress