我正在尝试为开发环境运行docker容器。我使用下面的docker文件
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如下
# 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;
}
和Rails Env文件如下,
# 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;
我将DB(MySQL)保留在容器外部并与VM IP地址绑定。
构建docker镜像后,现在我正在尝试运行rake db:setup
但是我收到如下消息,
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)
同时如果我使用bash运行它,我可以在容器中运行rake db:setup
很想知道造成这个问题的原因!
答案 0 :(得分:1)
我希望这是因为您的WORKDIR
设置为/tmp
;尝试在/home/app/webapp
之后将其设置为RUN bundle install
。
我还注意到以下内容:
此行不会保存任何空格RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
;这些文件仍然存在于以前的图层中。
您在运行时覆盖CMD指令(CMD ["/sbin/my_init"]
);所以这个剧本中的任何内容都不会被运行。