-2

I am new docker. I am facing issue in Docker compose. please help me for that.

below is the my docker-compose.yaml file

version: "2"
services:

  database:
    image: mysql:5.7
    volumes:
      - ./data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
  wordpress:
    image: wordpress
    depends_on:
      - database
    ports:
      - "8080:80"
    restart: always
    environment:
        WORDPRESS_DB_HOST: database:3306
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress
        WORDPRESS_DB_NAME: wordpress
    volumes:
     db_data: {}

Below is the error i am getting. please help me to fix the error.

ERROR: The Compose file './docker-compose.yaml' is invalid because:
services.wordpress.volumes contains an invalid type, it should be an array
alt-f4
  • 2,112
  • 17
  • 49
  • https://hub.docker.com/_/mysql read it, - read the section : where to store data –  Aug 16 '20 at 09:21

1 Answers1

0

You mounted the database data onto the host, but used a (not declared) volume called db_data inside the wordpress service. I've gone ahead and added the db_data volume to the volumes list, added it as a volume to the database service.

I'm guessing you're using this setup for local development, so I've also mounted the wp-content folder from where you are running docker-compose up to /var/www/html/wp-content, so the files like uploads, plugins and themes can be stored inside version control/ are on your local machine and not inside the container.

version: "2"
services:

  database:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    image: wordpress
    depends_on:
      - database
    ports:
      - "8080:80"
    restart: always
    environment:
        WORDPRESS_DB_HOST: database:3306
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress
        WORDPRESS_DB_NAME: wordpress
    volumes:
      - "./wp-content:/var/www/html/wp-content"

volumes:
  db_data:
Tom
  • 4,070
  • 4
  • 22
  • 50