LoginSignup
4
3

More than 3 years have passed since last update.

【docker-compose】「Unsupported config option for services.~~」の解決方法

Posted at

docker-compose.ymlを作成し、railsアプリケーションを立ち上げようとしたとき、題名のようなエラーが発生しました。
また、このときのdocker-compose.ymlファイルは以下のようにしていました。

ターミナル
 docker-compose run --rm app rails new . --force --database=mysql --skip-bundle
エラー内容
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.app: 'context'
Unsupported config option for services.web: 'context'
Unsupported config option for services.volumes: 'db-data'
services.app.build contains an invalid type, it should be a string, or an object
services.web.build contains an invalid type, it should be a string, or an object
docker-compose.yml
version: '3'
services:
    app:
        build:
        context: .
        env_file:
            - ./environments/db.env
        command: bundle exec puma -C config/puma.rb
        volumes:
            - .:/webapp
            - public-data:/webapp/public
            - tmp-data:/webapp/tmp
            - log-data:/webapp/log
        depends_on:
            - db
    db:
        image: mysql:5.7
        env_file:
            - ./environments/db.env
        volumes:
            - db-data:/var/lib/mysql
    web:
        build:
        context: containers/nginx
        volumes:
            - public-data:/webapp/public
            - tmp-data:/webapp/tmp
        ports:
            - 80:80
        depends_on:
            - app
    volumes:
        public-data:
        tmp-data:
        log-data:
        db-data:

解決方法

結論からいうと、インテンドのやり方がまずかったようです。
エラーが出た箇所のインテンドのやり方が違うようで、意識せずにインテンドをずらしていたので心当たりがありました。
これを以下のように直すと、無事コードが走りました。

docker-compose.yml
version: '3'
services:
  app:
    build:
      context: .
    env_file:
      - ./environments/db.env
    command: bundle exec puma -C config/puma.rb
    volumes:
      - .:/webapp
      - public-data:/webapp/public
      - tmp-data:/webapp/tmp
      - log-data:/webapp/log
    depends_on:
      - db
  db:
    image: mysql:5.7
    env_file:
      - ./environments/db.env
    volumes:
      - db-data:/var/lib/mysql
  web:
    build:
      context: containers/nginx
    volumes:
      - public-data:/webapp/public
      - tmp-data:/webapp/tmp
    ports:
      - 80:80
    depends_on:
      - app
volumes:
  public-data:
  tmp-data:
  log-data:
  db-data:
4
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
4
3