Extension fieldsを使ってdocker-composeのコンテナ設定を共通化する

公開日時

docker-composeのversion 3.4以降のフォーマットからExtension fieldsという機能が使えるようになったとのこと。

これを使うとコンテナ設定の共通化ができる。

Railsで非同期処理をする際にsidekiqのコンテナを用意したかったので、Extension fieldsを使ってRailsコンテナ設定を共通化してcommandだけそれぞれで変えるようにした。

version: "3.7"

x-app: &app
  build:
    context: .
    dockerfile: ./docker/ruby/Dockerfile

services:
  app:
    <<: *app
    command: ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
  sidekiq:
    <<: *app
    command: ["bundle", "exec", "sidekiq", "-C", "config/sidekiq.yml"]

参考


Related #docker

docker-credential-desktop.exe not installed or not available in PATH

rm ~/.docker/config.jsonしたら起動できた

Cloud Datastoreのローカル環境をDockerで構築する

CloudDatastoreエミュレータとgoogle-cloud-guiの環境を構築

docker-composeコマンドのエイリアスを作る

dcコマンドを置き換えた

Dockerでpt-query-digestを使う

コンテナのおかげで手軽にslowlog分析ができるようになった

mysqld: [Warning] World-writable config file '/etc/mysql/conf.d/my.cnf' is ignored.

windowsだとvolume mountすると777になるのでDockerfileを作ってcopyするようにした