我想用 Docker 部署一个 Rails 应用。
Dockerfile 的内容如下:
FROM ruby:2.2.2
ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ADD Gemfile $APP_HOME/Gemfile
ADD Gemfile.lock $APP_HOME/Gemfile.lock
ADD init.sh $APP_HOME/
RUN export LANG=C.UTF-8 && bundle install
ADD . $APP_HOME
CMD ["sh", "init.sh"]
init.sh 程序执行脚本内容如下:
#!/bin/sh
bundle exec rake db:setup
bundle exec rake db:seed_fu
bundle exec sidekiq -C config/sidekiq.yml
bundle exec rails server -b 0.0.0.0
当我编译完这个程序镜像:
docker build -t myapp .
运行它时:
docker run --name web -d -p 3000:3000 myapp
从日志中看到:
docker logs web
init.sh: 2: init.sh: bundle: not found
init.sh: 3: init.sh: bundle: not found
init.sh: 4: init.sh: bundle: not found
init.sh: 5: init.sh: bundle: not found
是执行 bundle
的路径问题,怎么指定正确的路径呢?
bundle is not installed. Please install bundle before executing bundle command.
If you are sure and sure that the bundle is installed, it should be a problem with the environment variables, which was not found. Use
which bundle
to find it and modify the environment variables before executing bundle.