bilby91
bilby91

Reputation: 904

docker issue rails asset precompile boot2docker

I'm trying to get the assets compilation right on my container (running on boot2docker).

I currently have one docker image for pg database and the web app container. I don't know why the precompiled assets are not showing after a successful build.

My Dockerfile looks like this:

FROM ruby:2.2.0

RUN apt-get update -qq && apt-get install -y build-essential

# Postgres support
RUN apt-get install -y libpq-dev

# Nokogiri support
RUN apt-get install -y libxml2-dev libxslt1-dev

# JS runtime
RUN apt-get install -y nodejs

ENV APP_HOME /app

RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/tmp
RUN mkdir $APP_HOME/log

# Copy the Gemfile and Gemfile.lock into the image.
# Temporarily set the working directory to where they are.
WORKDIR /tmp
ADD Gemfile Gemfile
ADD Gemfile.lock Gemfile.lock

# Install ruby dependencies
RUN bundle install

# Add app to container
ADD . $APP_HOME

# Add container working directory
WORKDIR $APP_HOME

# Expose puma port
EXPOSE 3000

# Expose the assets directory
VOLUME /app/public

# Precompile js/scss assets
RUN bundle exec rake assets:precompile

# Run puma server
CMD bundle exec puma -C /app/puma.rb

docker-compose.yml

db:
  image: postgres
web:
  build: .
  volumes:
    - .:/app
    - /mnt/docker/app/public:/app/public
  links:
    - db
  environment:
    VIRTUAL_HOST: app.dev

When I check /mnt/docker/app/public there is nothing :(.

Upvotes: 1

Views: 573

Answers (2)

bilby91
bilby91

Reputation: 904

Thanks for the help Michael, also I had to change the order of the commands.

I had to do the assets compilation before making the directory a volume.

So, changed like this:

...

# Add container working directory
WORKDIR $APP_HOME

# Expose puma port
EXPOSE 3000

# Precompile js/scss assets
RUN bundle exec rake assets:precompile

# Expose the assets directory
VOLUME /app/public

# Run puma server
CMD bundle exec puma -C /app/puma.rb

Is this the expected behaviour ?

Upvotes: 1

Michael
Michael

Reputation: 10474

You are precompiling your assets in your Dockerfile, however, you are then mounting over them with your volumes in your compose file. Remove - /mnt/docker/app/public:/app/public from your compose file and then restart the container.

if you want to see what is in /app/public then do

docker run -it --volumes-from=<APP_CONTAINER_NAME> <IMAGE> ls /app/public 

or something similar.

Upvotes: 1

Related Questions