Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake task seems not to write files in a Docker container

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?

like image 296
Bartek Kruszczyński Avatar asked Aug 07 '15 08:08

Bartek Kruszczyński


People also ask

What is a rake task?

Rake is a software task management and build automation tool created by Jim Weirich. It allows the user to specify tasks and describe dependencies as well as to group tasks in a namespace. It is similar in to SCons and Make.

Which docker command is used to attach to a running container?

Use docker attach to attach your terminal's standard input, output, and error (or any combination of the three) to a running container using the container's ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.


1 Answers

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.

like image 52
Henrik Sachse Avatar answered Oct 27 '22 00:10

Henrik Sachse