I'm trying to run my Rails app in production locally as part of platform migration. I'm using Docker with Docker Compose.
I've ran into issues with rake assets:precompile
. It look as if the docker deletes the generated files during build.
Here's my Dockerfile
FROM ruby:2.2.2
RUN apt-get update -qq && apt-get install -y build-essential nodejs npm nodejs-legacy mysql-client vim
RUN mkdir /lunchiatto
ENV RAILS_ENV production
ENV RACK_ENV production
WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install --without production test
ADD . /myapp
WORKDIR /myapp
RUN bundle exec rake assets:clobber
RUN bundle exec rake assets:precompile --trace
And here's my docker-compose.yml
db:
image: postgres:9.4.1
ports:
- "5432:5432"
environment:
RACK_ENV: production
RAILS_ENV: production
web:
build: .
command: bundle exec puma -C config/puma.rb
ports:
- "3000:3000"
links:
- db
volumes:
- .:/myapp
environment:
RACK_ENV: production
RAILS_ENV: production
The docker-compose build
command runs fine. I've also inserted RUN ls -l /myapp/public/assets
into Dockerfile
before and after the rake assets:precompile
and all seems fine. However if I run docker-compose run web ls -l /myapp/public/assets
after the build with the docker-compose up
running in a different tab all the asset's files are gone.
It's unlikely that the container is readonly during build, so what could that be?
You hide the containers folder /myapp
by a volume that you mount from your local folder .
.
You need to make sure that the required files are inside the local folder when you want to mount it. When you do not mount that folder the files would be available on your image.
The effect is similar to a Linux system: when you have files in a folder /my/folder
and you mount a disk to the same folder the original files are hidden. Instead the files from that disk are visible.