Home > Mobile >  Docker throws "(root) Additional property mysql is not allowed" when i try to set up local
Docker throws "(root) Additional property mysql is not allowed" when i try to set up local

Time:10-27

when I try to create a local WordPress development environment using docker, it throws an error

(root) Additional property MySQL is not allowed

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

command i used : Docker compose up -d

CodePudding user response:

This yaml code works fine

    services:
  db:
    # 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
    command: '--default-authentication-plugin=mysql_native_password'
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=somewordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
    expose:
      - 3306
      - 33060
  wordpress:
    image: wordpress:latest
    volumes:
      - wp_data:/var/www/html
    ports:
      - 80:80
    restart: always
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=wordpress
      - WORDPRESS_DB_NAME=wordpress
volumes:
  db_data:
  wp_data:

CodePudding user response:

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:

  1. Indent the entire file one step, and add an unindented services: line above the existing content.
  2. Above that, add another line version: '3.8' (or '2.4').
  3. Delete the obsolete links: block; Compose provides network setup for you so this isn't required.
version: '3.8'
services:
  web:
    image: wordpress
    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

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.

  • Related