ruby-on-railsrubydockerforeman

Foreman not found on docker


I'm trying to create a docker file to run my rails application. When I try and start the container it fails with foreman: executable file not found in $PATH.

Dockerfile

FROM ruby:2.7.2 as builder
ENV RAILS_ENV="production"
COPY . /app
WORKDIR /app
RUN gem install bundler:2.1.4
RUN apt-get update && apt-get install -y nodejs libpq-dev build-essential patch --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN bundle config set deployment 'true' && \
    bundle config set without 'development test'
RUN bundle install
RUN gem install foreman

FROM ruby:2.7.2
ENV RAILS_ENV="production" \
    RAILS_SERVE_STATIC_FILES="yes"
    # SECRET_KEY_BASE="your_production_key" \
# RUN install_packages libssl1.1
COPY --from=builder /app /app
WORKDIR /app
EXPOSE 3000
CMD ["foreman", "start"]

Solution

  • You installed foreman in the builder, but you are executing it in the main container.

    If you want to run a program in the container, you need to install it.