David Geismar
David Geismar

Reputation: 3422

Rails api Docker container fails on startup (failed to load command: rails) when started with other services

I have several docker services running in conjunction together through a docker-compose file.

version: '3'
services:
  redis-server:
    image: redis
  scraper:
    image: davidgeismar/artifacts-scraper:without-db
    command: 'ruby ./scrape_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_scraper
    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_scraper.rb 2>&1 | tee ./log/sidekiq.log'
    volumes:
      - ./:/usr/src/artifacts_scraper
    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

The problem is with the data_api ( a rails api) service that works fine when I run it alone with its docker file :

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"]

However when I run it with the other services through the docker-compose file : docker-compose pull && docker-compose up --build

I get :

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'

I dont how the service could run fine when launch by itself, and fail on startup when run through docker-compose with other services.

You can find the github projects here :

https://github.com/davidgeismar/artifacts-scraper/tree/removing-db https://github.com/davidgeismar/artifacts_data_api

and on docker hub :

https://hub.docker.com/repository/docker/davidgeismar/artifacts-scraper

https://hub.docker.com/repository/docker/davidgeismar/artifacts_data_api

Upvotes: 2

Views: 4530

Answers (1)

Try starting your image in the dockerfile with this

CMD bundle exec rails s -p 3000 -b '0.0.0.0'

And delete this line in your docker-compose.yml under data_api

command: bundle exec rails s -p 3000 -b '0.0.0.0'

Upvotes: 1

Related Questions