ruby-on-railsrubydocker

docker run error: "unable to start container process: exec: "build": executable file not found in $PATH: unknown"


I am trying to dockerize a Rails app, but I am getting this error:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "build": executable file not found in $PATH: unknown.

Here is my Dockerfile:

FROM ruby:3.1.2-bullseye as base

RUN apt-get update -qq && apt-get install -y build-essential apt-utils libpq-dev nodejs

WORKDIR /docker/app

RUN gem install bundler

COPY Gemfile* ./

RUN bundle install

ADD . /docker/app

RUN bundle exec rake assets:precompile 

ARG DEFAULT_PORT 3000

EXPOSE ${DEFAULT_PORT}


# CMD ["rails","server"] # you can also write like this.
CMD ["build", "exec", "rails", "server", "-b", "0.0.0.0"]

The Docker commands I'm running:

docker build -t rail-app:12.0 .
docker run -d -p 3040:3000 rails-app:12.0

How do I solve this issue?


Solution

  • Looking through your dockerfile, I believe the error you're seeing happens because Docker can't find the executable build which you entered in your CMD line. The right way to start your Rails server in Docker should be to use bundle exec, which ensures commands run with the gems specified in your Gemfile. Modify your CMD to:

    CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
    

    After changing your Dockerfile, rebuild the image and run your container again.

    This setup should get your Rails app running smoothly in Docker.