I am trying to run docker container for development environment. I am using the below docker file
FROM phusion/passenger-ruby22:latest
# Set correct environment variables.
ENV HOME /root
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
# Expose Nginx HTTP service
EXPOSE 80
# Start Nginx / Passenger
RUN rm -f /etc/service/nginx/down
# Remove the default site
RUN rm /etc/nginx/sites-enabled/default
# Add the nginx site and config
ADD nginx.conf /etc/nginx/sites-enabled/webapp.conf
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf
# Install bundle of gems
WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN bundle install
# Add the Rails app
ADD . /home/app/webapp
RUN chown -R app:app /home/app/webapp
# Clean up APT and bundler when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
nginx.conf as below
# webapp.conf
server {
listen 80;
server_name localhost;
root /home/app/webapp/public;
passenger_enabled on;
passenger_user app;
passenger_ruby /usr/bin/ruby2.2;
}
and Rails Env file as below,
# rails-env.conf
# Set Nginx config environment based on
# the values set in the .env file
env PASSENGER_APP_ENV;
env RAILS_ENV;
env SECRET_KEY_BASE;
env APP_DEV_DB_HOST;
env APP_DEV_DB_DATABASE;
env APP_DEV_DB_PORT;
env APP_DEV_DB_USERNAME;
env APP_DEV_DB_PASSWORD;
I kept DB(MySQL) outside the container and binded with VM IP address.
After building the docker image, now I am trying to run rake db:setup
but I get the message as below,
sudo docker run -i -t -e "RAILS_ENV=development" -e "APP_DEV_DB_HOST=myipaddress" -e "APP_DEV_DB_DATABASE=SampleApp_Development" -e "APP_DEV_DB_PORT=3306" -e "APP_DEV_DB_USERNAME=sampleapp_dev" -e "APP_DEV_DB_PASSWORD=pass_dev" -e "PASSENGER_APP_ENV=development" sample_base rake db:setup
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
(See full trace by running task with --trace)
At the same time if I run this using bash, I am able to run rake db:setup
within the container
Curious to know what is causing this issue!.
I expect it's because your WORKDIR
is set to /tmp
; try setting it to /home/app/webapp
after RUN bundle install
.
I also noticed the following:
This line won't save any space RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
; the files will still exist in previous layers.
You override the CMD instruction (CMD ["/sbin/my_init"]
) at runtime; so whatever's in this script won't be run.