Bundle install and yarn install inside entry script – Docker

  docker, docker-compose, ruby-on-rails

I see that bundle install and yarn install are usually done in Dockerfile as:

RUN bundle install && yarn install

Which means that if I modify Gemfile or yarn.lock, I need to re-build the image again. I know that there is layer caching and the docker build will not rebuild other layers except bundle install && yarn install layer. But it means I have to do docker-compose up -d --build

But I was wondering if it is ok to put these commands inside an entry script of docker-compose or in command as:

command: bundle install && yarn install && rails s

In this way, I believe, whenever I do docker-compose up -d, bundle install and yarn install will be executed without having to build the image.

Not sure if it has any advantages over conventional bundle install in Dockerfile except not having to append --build in docker-compose up. Correct that if I do this, bundle install and yarn install will get executed even when there are no changes to Gemfile or Yarn files. I guess this is one of the bad sides.

Please correct me if it is not the ideal way to go.

New to docker world.

Source: StackOverflow