LoginSignup
3
3

More than 3 years have passed since last update.

「ERROR: The Compose file is invalid」となったクソしょうもない原因

Posted at

その状況

docker-compose.yml

version: '3'

services:

  (略)

db:
    image: mysql:5.7
    container_name: db-host
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: database
      MYSQL_USER: docker
      MYSQL_PASSWORD: docker
      TZ: 'Asia/Tokyo'
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    volumes:
    - ./docker/db/data:/var/lib/mysql
    - ./docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
    - ./docker/db/sql:/docker-entrypoint-initdb.d
    ports:
    - 3306:3306

とdocker-compose.ymlを書き、docker-compose upしてみると

ERROR: The Compose file '.\docker-compose.yml' is invalid because:
Invalid top-level property "db". Valid top-level sections for this Compose file are: version, services, networks, volumes, and extensions starting with "x-".

You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

こんなエラーが…
「お前のファイルさ、書き方がなってないから無効な。公式のやつ見て来いよ」てなことを言われるのでした。

公式やほかの人たちのと比べてもいろいろ直したのだが通らず。小一時間格闘する羽目に。

判明した原因

半角スペースがないこと。

docker-compose.yml
version: '3'

services:

  (略)

db:
    image: mysql:5.7
    container_name: db-host

db:の前に半角スペースがなくservicesと同じ列にあることがわかります。
dbservicesとして定義するためこのままではエラーが出てしまうのでした。

docker-compose.yml
version: '3'

services:

  (略)

 db:
    image: mysql:5.7
    container_name: db-host

半角スペースを入れてdocker-compose upすると無事に通りました。
dockerが厳しいというより、ただのしょうもないミスでした。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3