When attempting to set up a local WordPress development environment using Docker, I encountered an error message stating that:
(root) Additional property MySQL is not allowed
The error occurred when I ran the command docker compose up -d
with the following Docker Compose file:
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=password
ports:
- "127.0.0.3:8080:80"
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=my-wpdb
2
Answers
This yaml code works fine
It looks like you’ve found a very very old example using the "version 1" Compose format. For a long time, the Docker Compose tool interpreted files without a
version:
line as being in this format, but more recently the tool has changed to interpret these lines as being in a much newer, and somewhat incompatible, "Compose Specification" format.I’d recommend using either version 2 or version 3 of the Compose file format (version 2 has some resource-constraint options for non-Swarm hosts that are often useful). In spite of the Docker documentation claiming they’re "legacy", every version of Compose from the past several years supports these.
For the file you show, the required changes are straightforward:
services:
line above the existing content.version: '3.8'
(or'2.4'
).links:
block; Compose provides network setup for you so this isn’t required.The newer file format has support for declaring named volumes in the Compose file itself, which would let you declare storage for the database, and @ioeshu’s extended example includes the relevant
volumes:
blocks.