Docker For Rails Developers - Chapter 2 Defining Our First Custom Image WORKDIR Correctoin

Dockerfile:

FROM ruby:2.6

RUN apt-get update -yqq
RUN apt-get install -yqq --no-install-recommends nodejs

COPY . /usr/src/app/

WORKDIR /usr/src/app/

RUN bundle install

The Dockerfile instructs us to copy the current directory into /usr/src/app/. Placing our directory myapp into /usr/src/app/.

Then the WORKDIR is defined as /usr/src/app/

And RUN bundle install.

This fails as bundle install should be run in the app directory. We’re in /usr/src/app/ but we should be in /usr/src/app/myapp.

The Dockerfile is corrected with

FROM ruby:2.6

RUN apt-get update -yqq
RUN apt-get install -yqq --no-install-recommends nodejs

COPY . /usr/src/app/

WORKDIR /usr/src/app/myapp

RUN bundle install
2 Likes

I made the change you suggest, now get this:
/usr/local/bundle/gems/webpacker-4.3.0/lib/webpacker/configuration.rb:95:in `rescue in load’: Webpacker configuration file not found /usr/src/app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /usr/src/app/config/webpacker.yml (RuntimeError)

Can anyone help? Frustrating to pay so much for a book that is incorrect.

1 Like

I ended up with a different solution and believe my original problem was a wrong file structure.

My Dockerfile is now located in the Rails app - myapp. The value of WORKDIR is /usr/src/app/.

Is that how you have yours now?

2 Likes
  • myapp should be your current directory. (cd myapp)
  • The Dockerfile should be created in the myapp directory–it looks like you created it one directory above.
  • docker build . will then succeed, I think.
1 Like

I had this error when I was going through the book using Rails 6.1.

The problem is that the steps in the book don’t allow webpacker to be installed, and you’re seeing an error because its config file isn’t present.

I posted a topic about what I had to change to use Rails 6.1 here. It will fix your problem if you’re using Rails 6.1, and may fix it even if you’re using an older version of Rails.

1 Like