B
B
Bogdan2018-05-11 12:19:31
Docker
Bogdan, 2018-05-11 12:19:31

docker-compose optimization?

Hello. Tell me please. I have 2 identical containers that differ only in command sections . Is it possible to somehow write more concisely and indicate that one container would inherit the other, thereby removing duplication and copy-paste? Thank you.

app:
    build:
      context: .
      args:
        APP_HOME: $APP_HOME
    command: >
      bash -c "
      bundle check
      || bundle install --clean
      && rm -f tmp/pids/server.pid
      && bundle exec rails db:migrate
      && bundle exec rails server"
    ports:
      - $PORT:$PORT
    volumes:
      - .:$APP_HOME
    environment:
      DATABASE_URL: postgresql://$POSTGRES_USER:[email protected]$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB?pool=$POSTGRES_POOL
      REDIS_PROVIDER: redis://:[email protected]$REDIS_HOST:$REDIS_PORT?db=$REDIS_DB
      BUNDLE_PATH: ${APP_HOME}/gems
    env_file:
      - .env
    depends_on:
      - db
      - redis
      
  sidekiq:
    build:
      context: .
      args:
        APP_HOME: $APP_HOME
    command: bundle exec sidekiq -C config/sidekiq.yml
    volumes:
      - .:$APP_HOME
    environment:
      DATABASE_URL: postgresql://$POSTGRES_USER:[email protected]$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB?pool=$POSTGRES_POOL
      REDIS_PROVIDER: redis://:[email protected]$REDIS_HOST:$REDIS_PORT?db=$REDIS_DB
      BUNDLE_PATH: ${APP_HOME}/gems
    env_file:
      - .env

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Bragin, 2018-05-11
@smiley

https://docs.docker.com/compose/extends/#extending...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question