我有几个通过docker-compose文件一起运行的docker服务。
version: '3'
services:
redis-server:
image: redis
scrapper:
image: davidgeismar/artifacts-scrapper:without-db
command: 'ruby ./scrap_sources.rb'
environment:
- REDIS_URL=redis://redis-server:6379/0
- ARTIFACTS_ENV=docker_development
- DATA_API_BASE=http://data_api:3000
volumes:
- .:/usr/src/artifacts_scrapper
depends_on:
- data_api
- redis-server
data_api:
image: davidgeismar/artifacts_data_api:latest
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/artifacts_data_api
environment:
- RAILS_ENV=docker_development
- SECRET_KEY_BASE=docker_development_secret
sidekiq:
build: .
command: 'bundle exec sidekiq -r ./artifacts_scrapper.rb 2>&1 | tee ./log/sidekiq.log'
volumes:
- ./:/usr/src/artifacts_scrapper
environment:
- REDIS_URL=redis://redis-server:6379/0
- ARTIFACTS_ENV=docker_development
- DATA_API_BASE=http://data_api:3000
depends_on:
- redis-server
- data_api
问题出在data_api(rails api)服务,当我与它的docker文件一起单独运行它时,它可以正常工作:
FROM ruby:2.6.3
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /artifacts_data_api
WORKDIR /artifacts_data_api
COPY Gemfile /artifacts_data_api/Gemfile
COPY Gemfile.lock /artifacts_data_api/Gemfile.lock
RUN gem install bundler
RUN gem install rails
RUN bundle install
COPY . /artifacts_data_api
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
但是,当我通过docker-compose文件与其他服务一起运行它时:docker-compose pull && docker-compose up --build
我明白了:
data_api_1 | bundler: failed to load command: rails (/usr/local/bundle/ruby/2.6.0/bin/rails)
data_api_1 | Bundler::GemNotFound: Could not find concurrent-ruby-1.1.5 in any of the sources
data_api_1 | /usr/local/bundle/gems/bundler-2.1.4/lib/bundler/spec_set.rb:86:in `block in materialize'
我不知道该服务在单独启动时如何运行良好,而在通过docker-compose与其他服务一起运行时在启动时失败。
您可以在这里找到github项目:
https://github.com/davidgeismar/artifacts-scrapper/tree/removing-dbhttps://github.com/davidgeismar/artifacts_data_api
和docker hub:
https://hub.docker.com/repository/docker/davidgeismar/artifacts-scrapper
https://hub.docker.com/repository/docker/davidgeismar/artifacts_data_api
尝试使用此命令在dockerfile中启动映像
CMD bundle exec rails s -p 3000 -b '0.0.0.0'
并在data_api下的docker-compose.yml中删除此行
command: bundle exec rails s -p 3000 -b '0.0.0.0'