7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

docker-compose.ymlを書いたらチェッカー入れてみようねって話

7
Last updated at Posted at 2019-10-28

なんか怒られるようになった・・・

services.web.environment.ports contains ["3000:3000"], which is an invalid type, it should be a string, number, or a null

書いてるのはお馴染みの下記の記述。

ports:
  - 3000:3000

妙なのはdbコンテナでは上記で書けて、webコンテナでは書けないと言うこと。

 原因解明

質問したら、ワンパンで解決。

 インデントずれてね?

そう、インデントがずれていたのである。私のエディタでは全角のインデントを可視化させているので、視覚的に妙なインデントになるのを防ぐようにしてて安心しきってたんですが、純粋に階層が1つ深くなった状態になってたんですね。

docker-compose.yml
  web:
    build: .
    command: ["/bin/sh", "-c", "yarn install && cd product_name && bundler exec rails s -p 3000 -b '0.0.0.0'"]
    environment:
      BUNDLE_APP_CONFIG: /web/.bundle
      ports:
       - 3000:3000
      depends_on:
       - db

上記のようになったたんですね。正解は、下記です。

docker-compose.yml
  web:
    build: .
    command: ["/bin/sh", "-c", "yarn install && cd product_name && bundler exec rails s -p 3000 -b '0.0.0.0'"]
    environment:
      BUNDLE_APP_CONFIG: /web/.bundle
    ports:
      - 3000:3000
    depends_on:
      - db

いやー、微妙。すごい見つけずらい。でもこうしないと、ymlの記述の型がおかしくて怒られるようになるので、注意しないといけないです。で、オススメされたのがこちら。

code-beautify

これのyamlチェッカーを使うと、ミスが減るんじゃないでしょうかとのこと。確かにその通りなので、以降使っていきたいと思います。

7
10
1

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
7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?