2021-11-08 10:41:35 +00:00
## WordPress with MySQL
This example defines one of the basic setups for WordPress. More details on how this works can be found on the official [WordPress image page ](https://hub.docker.com/_/wordpress ).
2020-03-18 20:31:31 +00:00
Project structure:
```
.
2022-05-10 09:59:25 +00:00
├── compose.yaml
2020-03-18 20:31:31 +00:00
└── README.md
```
2022-05-10 09:59:25 +00:00
[_compose.yaml_ ](compose.yaml )
2020-03-18 20:31:31 +00:00
```
services:
db:
2021-11-08 10:41:35 +00:00
# We use a mariadb image which supports both amd64 & arm64 architecture
image: mariadb:10.6.4-focal
# If you really want to use MySQL, uncomment the following line
#image: mysql:8.0.27
2020-03-18 20:31:31 +00:00
...
wordpress:
image: wordpress:latest
ports:
- 80:80
restart: always
...
```
2022-05-10 09:59:25 +00:00
When deploying this setup, docker compose maps the WordPress container port 80 to
2020-03-18 20:31:31 +00:00
port 80 of the host as specified in the compose file.
2021-11-08 10:41:35 +00:00
> ℹ ️ **_INFO_**
> For compatibility purpose between `AMD64` and `ARM64` architecture, we use a MariaDB as database instead of MySQL.
> You still can use the MySQL image by uncommenting the following line in the Compose file
> `#image: mysql:8.0.27`
2022-05-10 09:59:25 +00:00
## Deploy with docker compose
2020-03-18 20:31:31 +00:00
```
2022-05-10 09:59:25 +00:00
$ docker compose up -d
2020-03-18 20:31:31 +00:00
Creating network "wordpress-mysql_default" with the default driver
Creating volume "wordpress-mysql_db_data" with default driver
...
Creating wordpress-mysql_db_1 ... done
Creating wordpress-mysql_wordpress_1 ... done
```
## Expected result
Check containers are running and the port mapping:
```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5fbb4181a069 wordpress:latest "docker-entrypoint.s…" 35 seconds ago Up 34 seconds 0.0.0.0:80->80/tcp wordpress-mysql_wordpress_1
e0884a8d444d mysql:8.0.19 "docker-entrypoint.s…" 35 seconds ago Up 34 seconds 3306/tcp, 33060/tcp wordpress-mysql_db_1
```
2021-11-08 10:41:35 +00:00
Navigate to `http://localhost:80` in your web browser to access WordPress.
2020-03-18 20:31:31 +00:00
![page ](output.jpg )
Stop and remove the containers
```
2022-05-10 09:59:25 +00:00
$ docker compose down
2020-03-18 20:31:31 +00:00
```
2021-11-08 10:41:35 +00:00
To remove all WordPress data, delete the named volumes by passing the `-v` parameter:
2020-03-18 20:31:31 +00:00
```
2022-05-10 09:59:25 +00:00
$ docker compose down -v
2021-05-21 16:56:18 +00:00
```