Docker Compose文件中的问题

时间:2020-08-16 08:34:56

标签: docker-compose sbt-docker-compose

我是新码头工人。我在Docker compose中面临问题。请帮我。

下面是我的docker-compose.yaml文件

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: {}

以下是我遇到的错误。请帮助我解决错误。

ERROR: The Compose file './docker-compose.yaml' is invalid because:
services.wordpress.volumes contains an invalid type, it should be an array

1 个答案:

答案 0 :(得分:0)

您将数据库数据安装到主机上,但是在db_data服务内部使用了一个名为wordpress的卷(未声明)。我已经将db_data卷添加到卷列表中,并将其作为卷添加到database服务中。

我猜您正在使用此设置进行本地开发,因此我还将wp-content文件夹从运行docker-compose up的位置安装到/var/www/html/wp-content,因此文件诸如上载,插件和主题之类的内容可以存储在版本控制中,或者存储在本地计算机上,而不是容器内。

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: