【问题标题】:docker-compose error when I run bundle当我运行捆绑包时,docker-compose 错误
【发布时间】:2016-05-14 19:42:11
【问题描述】:

当我运行一些类似这样的任务时,我的 gemfile 或 bundle 出现错误:

docker exec -it webapp_web_1 bundle exec rake db:migrate

错误:找不到 Gemfile 或 .bundle/ 目录

或者这个命令:

docker-compose logs worker

log:
Attaching to webapp_worker_1
worker_1 | Could not locate Gemfile or .bundle/ directory

Dockerfile:

# === 1 ===
FROM phusion/passenger-ruby22:0.9.18
MAINTAINER Israel Barba Aceves "israel@yotepresto.com"

# Set correct environment variables.
ENV HOME /root

RUN apt-get update && apt-get install -y libqt4-dev libqtwebkit-dev imagemagick

# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]


# === 2 ===
# Start Nginx / Passenger
RUN rm -f /etc/service/nginx/down

# === 3 ====
# Remove the default site
RUN rm /etc/nginx/sites-enabled/default


# Add the nginx info
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf

# === 4 ===
# Prepare folders
RUN mkdir /home/app/webapp



# === 5 ===
# Run Bundle in a cache efficient way
WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN bundle install


#WORKDIR /webapp
#RUN RAILS_ENV=staging rake assets:precompile --trace

# === 6 ===
# Add the rails app
ADD . /home/app/webapp

RUN mkdir /home/app/webapp/tmp/cache/assets/staging
RUN mkdir /home/app/webapp/tmp/cache/assets/staging/sprockets
# RUN chown -R app:app /home/app/webapp/tmp/cache/assets/staging
RUN chown -R app:app /home/app/webapp

#RAILS_ENV=staging rake assets:precompile


# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

docker-compose.yml

db:
  image: postgres
  ports:
    - "5432"
  volumes:
    - ytp-postgres:/var/lib/postgresql/data

redis:
  image: redis
  ports:
    - "6379" 
  volumes:
    - ytp-redis:/var/lib/redis/data


web:
  build: .
  volumes:
    - .:/web
  ports:
    - "80"
  links:
    - redis
    - db
  environment:
    RACK_ENV: staging
    RAILS_ENV: staging

worker:
  build: .
  volumes_from:
    - web
  command: bundle exec sidekiq -e s -c 5 -C config/sidekiq.yml
  environment:
    RAILS_ENV: staging
  links:
    - redis
    - db

我也无法从我的配置中启动 Sidekiq,我猜这与卷有关,但我不确定,我已经以多种方式编辑了这个文件但没有成功......有什么建议吗?

Docker 版本: 1.9.1

Docker-compose 版本 1.6.0rc2

谢谢。

【问题讨论】:

  • 当你运行“docker-compose run web bundle exec rake db:migrate”时会发生什么?
  • 同样的错误:找不到 Gemfile 或 .bundle/ 目录我必须在容器内运行迁移
  • 另外,sidekiq 是您项目中的瑰宝,您是否有理由在单独的容器中运行它?由于您的 web 容器已经链接到 redis,我建议使用 web 容器中的 sidekiq 并使用 foreman 一起运行 sidekiq 和 rails 服务器。
  • 性能好吗?我会考虑那个解决方案,我想知道为什么像 RAKE 这样的其他任务会引发错误?

标签: ruby-on-rails docker redis sidekiq docker-compose


【解决方案1】:

您必须修改 Dockerfile 的最后一部分以匹配 docker compose 文件的文件夹:

WORKDIR /web
ADD Gemfile /web/
ADD Gemfile.lock /web/
RUN bundle install

【讨论】:

  • @TopperH 这对我有用,但我无法解释 - 你能指出我的任何文档以进一步了解这一点吗?
  • @mattsch,我认为 OP 配置背后的想法是您不必每次更新 Gemfile 时都运行完整的捆绑安装。无论如何,这个配置已经过时了,现在我会坚持使用官方 ruby​​ 容器并按照官方文档设置一个 docker-compose 文件
猜你喜欢
  • 2021-12-28
  • 1970-01-01
  • 2019-03-26
  • 2019-04-04
  • 2020-12-17
  • 2021-08-27
  • 1970-01-01
  • 2021-11-29
  • 1970-01-01
相关资源
最近更新 更多