Having issues running bundle install with docker container - ruby-on-rails

I have an existing Rails application that I am just trying to turn into a docker instance. I've went through a few tutorials on dockerizing an existing rails app, but I keep getting stuck somewhere.
Here's my Dockerfile:
FROM ruby:2.5.1
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
I confirmed that my Gemfile.lock file in the local directory is empty.
Finally, here's my docker-compose.yml file:
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_HOST_AUTH_METHOD: trust
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- ./:/myapp
ports:
- "3000:3000"
depends_on:
- db
After running docker-compose build, it goes through the whole process of pulling down Ruby, postgresql, doing bundle install, etc... and then finally when I try to run docker-compose up, I get the following error:
web_1 | Bundler::GitError: The git source https://github.com/zdennis/activerecord-import is not yet checked out. Please run `bundle install` before trying to start your application
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/git/git_proxy.rb:235:in `allowed_in_path'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/git/git_proxy.rb:192:in `find_local_revision'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/git/git_proxy.rb:64:in `revision'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/git.rb:225:in `revision'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/git.rb:93:in `install_path'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/path.rb:126:in `expanded_path'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/path.rb:163:in `load_spec_files'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/git.rb:200:in `load_spec_files'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/path.rb:100:in `local_specs'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/source/git.rb:167:in `specs'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/definition.rb:759:in `block in converge_locked_specs'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/definition.rb:745:in `each'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/definition.rb:745:in `converge_locked_specs'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/definition.rb:248:in `resolve'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/definition.rb:171:in `specs'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/definition.rb:238:in `specs_for'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/definition.rb:227:in `requested_specs'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/runtime.rb:108:in `block in definition_method'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/runtime.rb:20:in `setup'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler.rb:107:in `setup'
web_1 | /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.6/lib/bundler/setup.rb:20:in `<top (required)>'
web_1 | /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
web_1 | /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
web_1 | bundler: failed to load command: rails (/usr/local/bundle/bin/rails)
What am I missing here? I would like to use an existing volume as myapp (not sure if there's any reason I shouldn't want to do this -- perhaps it runs faster if it's within the container itself?)
The only way I can get this to work properly is if I run docker-compose build, followed by docker-compose run web bundle install, followed by docker-compose up
Am I doing something wrong that's requiring me to have to run docker-compose run web bundle install? I saw it run when I ran docker-compose build, so not sure why it's required again.

Related

Rails fails to start on docker

I'm trying to setup my rails application to run using docker. It keeps crashing with Could not find rake-12.3.2 in any of the sources (Bundler::GemNotFound)
Dockerfile
FROM ruby:2.6.1
RUN apt-get update -yqq && \
apt-get install -yqq --no-install-recommends \
nodejs \
nano
COPY Gemfile* /usr/src/app/
WORKDIR /usr/src/app
RUN bundle install
RUN gem install foreman
RUN gem install rake -v 12.3.2
COPY . /usr/src/app/
CMD [ "bin/rails", "s", "-b", "0.0.0.0" ]
.docker-compose.yml
version: '3'
services:
postgres:
image: 'postgres:10.3-alpine'
volumes:
- 'postgres:/var/lib/postgresql/data'
env_file:
- '.env'
redis:
image: 'redis:4.0-alpine'
command: redis-server --requirepass yourpassword
volumes:
- 'redis:/data'
rails:
depends_on:
- 'postgres'
- 'redis'
build: .
ports:
- '3000:3000'
volumes:
- '.:/usr/src/app'
env_file:
- '.env'
volumes:
redis:
postgres:
config/boot.rb
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' if RUBY_PLATFORM =~ /darwin/
log
rails_1 | /usr/local/lib/ruby/site_ruby/2.6.0/bundler/spec_set.rb:91:in `block in materialize': Could not find rake-12.3.2 in any of the sources (Bundler::GemNotFound)
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler/spec_set.rb:85:in `map!'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler/spec_set.rb:85:in `materialize'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler/definition.rb:170:in `specs'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler/definition.rb:237:in `specs_for'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler/definition.rb:226:in `requested_specs'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler/runtime.rb:108:in `block in definition_method'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler/runtime.rb:20:in `setup'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler.rb:107:in `setup'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
rails_1 | from /usr/local/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
rails_1 | from /usr/src/app/config/boot.rb:3:in `<top (required)>'
rails_1 | from bin/rails:3:in `require_relative'
rails_1 | from bin/rails:3:in `<main>'
It looks like you are trying to pull down the current latest release of rake. You can remove the version declaration and let it auto resolve in this case.
Any reason this dependency is not in your Gemfile? Also, the rails app you are starting will include a dependency to rake. You should not need to install rake.

connection refused for Docker development environment

here are my configurations:
docker-compose.yml
---
web:
build: .
command: RAILS_ENV=production bundle exec rake assets:precompile --trace
command: foreman start
ports:
- "3000:3000"
links:
- postgres
environment:
- RAILS_ENV=production
- RACK_ENV=production
- POSTGRES_DATABASE=postgres
- POSTGRES_USERNAME=postgres
- POSTGRES_HOST=db
postgres:
image: postgres
Procfile
web: bundle exec puma -e _env:RAILS_ENV -C config/puma.rb
nginx: /usr/sbin/nginx -g 'daemon off;'
Dockerfile
# Generated by Cloud66 Starter
FROM ruby:2.2.3
RUN apt-get update -qq && apt-get install -y build-essential
RUN apt-get -y install curl \
git \
imagemagick \
libmagickwand-dev \
libcurl4-openssl-dev \
nodejs \
postgresql-client
# Installing your gems this way caches this step so you dont have to reintall your gems every time you rebuild your image.
# More info on this here: http://ilikestuffblog.com/2014/01/06/how-to-skip-bundle-install-when-deploying-a-rails-app-to-docker/
# Copy the Gemfile and Gemfile.lock into the image.
# Temporarily set the working directory to where they are.
WORKDIR /tmp
ADD Gemfile Gemfile
ADD Gemfile.lock Gemfile.lock
RUN gem install bundler
RUN bundle install
# Install and configure nginx
RUN apt-get install -y nginx
RUN rm -rf /etc/nginx/sites-available/default
ADD config/nginx.conf /etc/nginx/nginx.conf
# Add our source files precompile assets
ENV APP_HOME /app
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
ADD . $APP_HOME
# RUN RAILS_ENV=production bundle exec rake assets:precompile --trace
I build docker container with docker-compose and was successful:
docker-compose build
And here is output for docker-compose up
docker-compose up
⇒ docker-compose up
Starting watchhound_postgres_1
Starting watchhound_web_1
Attaching to watchhound_postgres_1, watchhound_web_1
postgres_1 | LOG: database system was interrupted; last known up at 2016-06-24 08:58:25 UTC
postgres_1 | LOG: database system was not properly shut down; automatic recovery in progress
postgres_1 | LOG: invalid record length at 0/1707C48
postgres_1 | LOG: redo is not required
postgres_1 | LOG: MultiXact member wraparound protections are now enabled
postgres_1 | LOG: database system is ready to accept connections
postgres_1 | LOG: autovacuum launcher started
web_1 | 09:04:46 web.1 | started with pid 6
web_1 | 09:04:46 nginx.1 | started with pid 7
web_1 | 09:04:47 web.1 | [6] Puma starting in cluster mode...
web_1 | 09:04:47 web.1 | [6] * Version 3.4.0 (ruby 2.2.3-p173), codename: Owl Bowl Brawl
web_1 | 09:04:47 web.1 | [6] * Min threads: 5, max threads: 5
web_1 | 09:04:47 web.1 | [6] * Environment: _env:RAILS_ENV
web_1 | 09:04:47 web.1 | [6] * Process workers: 1
web_1 | 09:04:47 web.1 | [6] * Phased restart available
web_1 | 09:04:47 web.1 | [6] * Listening on tcp://0.0.0.0:5000
web_1 | 09:04:47 web.1 | [6] * Listening on unix:///var/run/puma.sock
web_1 | 09:04:47 web.1 | [6] Use Ctrl-C to stop
web_1 | 09:04:49 web.1 | [6] - Worker 0 (pid: 12) booted, phase: 0
PROBLEM
Everything looks fine, but when I visit 192.168.99.100:5000 (from docker-machine ip) the browser says 192.168.99.100 refused to connect
Not sure what am I missing
My problem was with docker-compose.yml file, need to bind port 5000 not 3000 as per my overall configuration.

Error "Could not find rake-10.5.0 in any of the sources" on Phusion Passenger Docker image

I am trying to deploy a Rails app using Docker and the Phusion Passenger Ruby base image, but whenever I try to access the app from the browser I get this error:
web_1 | [ 2016-02-08 04:18:44.6861 31/7ff292141700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /home/app/webapp: An error occurred while starting up the preloader.
web_1 | Error ID: d3103e16
web_1 | Error details saved to: /tmp/passenger-error-EwymlW.html
web_1 | Message from application: <p>It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:</p>
web_1 |
web_1 | <pre class="commands">bundle install</pre>
web_1 |
web_1 | <p>If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:</p>
web_1 |
web_1 | <ol>
web_1 | <li>Is this app supposed to be run as the <code>app</code> user?</li>
web_1 | <li>Is this app being run on the correct Ruby interpreter? Below you will
web_1 | see which Ruby interpreter Phusion Passenger attempted to use.</li>
web_1 | </ol>
web_1 |
web_1 | <p>-------- The exception is as follows: -------</p>
web_1 | Could not find rake-10.5.0 in any of the sources (Bundler::GemNotFound)
web_1 | <pre> /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:92:in `block in materialize'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:85:in `map!'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:85:in `materialize'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:140:in `specs'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:185:in `specs_for'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/definition.rb:174:in `requested_specs'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/environment.rb:18:in `requested_specs'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:13:in `setup'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler.rb:127:in `setup'
web_1 | /var/lib/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/setup.rb:18:in `<top (required)>'
web_1 | /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
web_1 | /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
web_1 | /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:430:in `activate_gem'
web_1 | /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:297:in `block in run_load_path_setup_code'
web_1 | /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:435:in `running_bundler'
web_1 | /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:296:in `run_load_path_setup_code'
web_1 | /usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app'
web_1 | /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `<module:App>'
web_1 | /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
web_1 | /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'</pre>
web_1 |
web_1 |
web_1 | [ 2016-02-08 04:18:44.6935 31/7ff293143700 age/Cor/Con/CheckoutSession.cpp:277 ]: [Client 1-2] Cannot checkout session because a spawning error occurred. The identifier of the error is d3103e16. Please see earlier logs for details about the error.
This is my Dockerfile:
FROM phusion/passenger-ruby22:0.9.18
# Set correct environment variables.
ENV HOME /root
# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]
# Enable Nginx/Passenger
RUN rm -f /etc/service/nginx/down
# Enable portals virtual host
RUN rm /etc/nginx/sites-enabled/default
COPY portals.conf /etc/nginx/sites-enabled/portals.conf
RUN mkdir /home/app/webapp
# Load env vars into nginx
COPY rails-env.conf /etc/nginx/main.d/rails-env.conf
# Install gems dependencies
COPY Gemfile* /tmp/
WORKDIR /tmp
RUN bundle install
# Copy rails app
WORKDIR /home/app/webapp
COPY . ./
RUN chown -R app:app ./
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
I tried running bundler as RUN bundle install --deployment but it didn't work as well. I am passing RAILS_ENV and PASSENGER_APP_ENV via the rails-env.conf file and they are both set to production (which is the default according to the Passenger image docs).
If I docker exec -it bash <ID> into the container and run gem list I see that all the gems are installed, so I don't know what's wrong.
This error is due to out of date software. Because the passenger images are not updated frequently it is important to bring everything up to date in your Dockerfile. This is how I generally setup a Dockerfile based off a phusion image:
FROM phusion/passenger-ruby22:0.9.18
ENV SYSTEM_UPDATE=1
RUN apt-get update \
&& apt-get upgrade -y -o Dpkg::Options::="--force-confold" \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /home/app
COPY Gemfile /home/app/Gemfile
COPY Gemfile.lock /home/app/Gemfile.lock
RUN gem update --system && \
gem update bundler && \
bundle install --jobs 4 --retry 5
# The rest of your app setup here
ENTRYPOINT ["/sbin/my_init", "--"]
SYSTEM_UPDATE is just a cache buster variable. When I bump that up all the packages will be updated on the next docker build. It should be bumped frequently.
I also ensure gem and bundler are fully up to date before running bundle install.
Also, there is no benefit to copying your Gemfile and Gemfile.lock to the tmp directory, just copy it to your application directory.
You can remove your final Clean up APT when done. command - that's really not the right place for that. There should be a single RUN line that runs all the apt-get commands in a single layer.
Take a look at https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/ for the best practices around setting up a Dockerfile, especially the sections about using apt-get.
For me, rake was there, I fix it using
rake rails:update
have fun!

Sidekiq Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) on docker-compose

I'm trying to run sidekiq worker with Rails. When I try to docker-compose up worker I get the following error:
worker_1 | Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:332:in `rescue in establish_connection'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:318:in `establish_connection'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:94:in `block in connect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:280:in `with_reconnect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:93:in `connect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:351:in `ensure_connected'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:208:in `block in process'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:293:in `logging'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:207:in `process'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:113:in `call'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:211:in `block in info'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:57:in `block in synchronize'
worker_1 | /usr/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:57:in `synchronize'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:210:in `info'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq/cli.rb:71:in `block in run'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq.rb:84:in `block in redis'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:64:in `block (2 levels) in with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `handle_interrupt'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `block in with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `handle_interrupt'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq.rb:81:in `redis'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq/cli.rb:68:in `run'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/bin/sidekiq:13:in `<top (required)>'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/bin/sidekiq:23:in `load'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/bin/sidekiq:23:in `<main>'
nyvur_worker_1 exited with code 1
Here's my docker-compose file:
web: &app_base
build: .
ports:
- "80:80"
volumes:
- .:/Nyvur
command: /usr/bin/start_server.sh
links:
- postgres
- mongo
- redis
environment: &app_environment
SIDEKIQ_CONCURRENCY: 50
SIDEKIQ_TIMEOUT: 10
ENABLE_DEBUG_SERVER: true
RACK_ENV: production
RAILS_ENV: production
worker:
build: .
volumes:
- .:/Nyvur
ports: []
links:
- postgres
- mongo
- redis
command: bundle exec sidekiq -c 50
postgres:
image: postgres:9.1
ports:
- "5432:5432"
environment:
LC_ALL: C.UTF-8
POSTGRES_DB: Nyvur_production
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 3x1mpl3
mongo:
image: mongo:3.0.7
ports:
- "27017:27017"
redis:
image: redis
ports:
- "6379:6379"
My Dockerfile:
FROM phusion/passenger-customizable
MAINTAINER VodkaMD <support#nyvur.com>
ENV RACK_ENV="production" RAILS_ENV="production"
SECRET_KEY_BASE="e09afa8b753cb175bcef7eb5f737accd02a4c16d9b6e5d475943605abd4277cdf47c488812d21d9c7117efd489d876f34be52f7ef7e88b21759a079339b198ce"
ENV HOME /root
CMD ["/sbin/my_init"]
RUN /pd_build/utilities.sh
RUN /pd_build/ruby2.2.sh
RUN /pd_build/python.sh
RUN /pd_build/nodejs.sh
RUN /pd_build/redis.sh
RUN /pd_build/memcached.sh
RUN apt-get update && apt-get install -y vim nano dialog net-tools build-essential wget libpq-dev git
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# RUN mkdir /etc/nginx/ssl
# RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
RUN rm -f /etc/service/nginx/down
RUN rm -f /etc/service/redis/down
RUN rm -f /etc/service/sshd/down
RUN rm -f /etc/service/memcached/down
WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN mkdir /home/app/Nyvur
ADD . /home/app/Nyvur
RUN chown -R app:app /home/app/Nyvur
WORKDIR /home/app/Nyvur
RUN bundle install --deployment
RUN bundle exec rake assets:precompile
RUN rm /etc/nginx/sites-enabled/default
COPY config/nginx/nginx_nyvur.conf /etc/nginx/sites-enabled/nginx_nyvur.conf
ADD config/nginx/postgres-env.conf /etc/nginx/main.d/postgres-env.conf
ADD config/nginx/rails-env.conf /etc/nginx/main.d/rails-env.conf
ADD config/nginx/start_server.sh /usr/bin/start_server.sh
RUN chmod +x /usr/bin/start_server.sh
RUN mkdir -p /home/app/Nyvur/tmp/pids
RUN mkdir -p /home/app/Nyvur/tmp/sockets
RUN mkdir -p /home/app/Nyvur/log
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 80 443 9292
I've tried different configurations, I've checked other builds, but the problem still persists, So far, Sidekiq runs well outside of Docker.
Check if your redis server is running, start redis by using the following command in the terminal:
redis-server
Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
Your app tries to connect on the localhost interface of the container it is running in, but redis is running in a different container.
Modify your app config to use the link name of the redis container (redis in your case) as hostname for the connection.
On macOS (using Homebrew), I was able to fix this by running:
brew services start redis
If you haven't yet installed redis, you'll need to run the following first:
brew install redis
I have solved this error using the following snippet
sudo apt install redis-server
and then by running the redis-server using —
redis-server
Redis quick review
Had a similar issue, in my case I have a script that starts redis and other initial settings and I forgot to run it. It usually breaks with CaS (Tomcat) but this time it broke due to redis and I had all but forgotten that was being setup by the script.
Anyway to complement other answers, a quick way to check if there are issues is to run
redis-cli
Which will let you know if redis is working and therefore help you remember if you need to run it.
If Redi isn't running you'll get a redis console:
redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
If it is running you'll get a redis console (in interactive mode), see documentation:
redis-cli
127.0.0.1:6379>
For example you can say: PING and it will return PONG
redis-cli
127.0.0.1:6379> PING
PONG
To run the Redis Server don't forget to just do:
redis-server
Just start your redis server by using redis-server command.
After start sidekiq
If you are using heroku and having such problem then you need to specify REDIS_PROVIDER_URL in your env
Make sure you installed redis-server on your system :-
sudo apt install redis-server

limit logs amount for docker-compose

i have a rails project which i start with
docker-compose up
however each time i start it, docker-compose outputs logs for all previous containers, and its increasingly more and more...
how do i limit the output of logging on startup?
here's my docker-compose.yml, it it helps...
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
environment:
RAILS_ENV: development
volumes:
- .:/rcd
ports:
- "3000:3000"
external_links:
- postgres:db
volumes_from:
- bundle
bundle:
image: rcd_web
command: echo "hi"
volumes:
- /bundle
and here's Dockerfile:
FROM ruby:2.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
ENV APP_HOME /rcd
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ADD Gemfile* $APP_HOME/
ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
BUNDLE_JOBS=2 \
BUNDLE_PATH=/bundle
RUN bundle install --without production development test
ADD . $APP_HOME
ENV PATH ~/bin:$PATH
i can of course remove all old containers with:
docker rm `docker ps -aq`
but i dont want to do it on each startup..
here's f.ex. logging after three stop/start
~/workspace/rcd$ docker-compose up
Starting rcd_bundle_1...
Starting rcd_web_1...
Attaching to rcd_bundle_1, rcd_web_1
bundle_1 | hi
bundle_1 | hi
bundle_1 | hi
web_1 | => Booting WEBrick
web_1 | => Rails 4.2.4 application starting in development on http://0.0.0.0:3000
web_1 | => Run `rails server -h` for more startup options
web_1 | => Ctrl-C to shutdown server
web_1 | Exiting
web_1 | [2015-11-17 11:52:16] INFO WEBrick 1.3.1
web_1 | [2015-11-17 11:52:16] INFO ruby 2.1.7 (2015-08-18) [x86_64-linux]
web_1 | [2015-11-17 11:52:16] INFO WEBrick::HTTPServer#start: pid=1 port=3000
web_1 | [2015-11-17 11:52:16] FATAL SignalException: SIGTERM
web_1 | /usr/local/lib/ruby/2.1.0/webrick/server.rb:170:in `select'
web_1 | /usr/local/lib/ruby/2.1.0/webrick/server.rb:170:in `block in start'
web_1 | /usr/local/lib/ruby/2.1.0/webrick/server.rb:32:in `start'
web_1 | /usr/local/lib/ruby/2.1.0/webrick/server.rb:160:in `start'
web_1 | /bundle/gems/rack-1.6.4/lib/rack/handler/webrick.rb:34:in `run'
web_1 | /bundle/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
web_1 | /bundle/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'
web_1 | /bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
web_1 | /bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
web_1 | /bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
web_1 | /bundle/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
web_1 | /bundle/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
web_1 | bin/rails:8:in `require'
web_1 | bin/rails:8:in `<main>'
web_1 | [2015-11-17 11:52:16] INFO going to shutdown ...
web_1 | [2015-11-17 11:52:16] INFO WEBrick::HTTPServer#start done.
web_1 | => Booting WEBrick
web_1 | => Rails 4.2.4 application starting in development on http://0.0.0.0:3000
web_1 | => Run `rails server -h` for more startup options
web_1 | => Ctrl-C to shutdown server
web_1 | Exiting
web_1 | [2015-11-17 11:52:22] INFO WEBrick 1.3.1
web_1 | [2015-11-17 11:52:22] INFO ruby 2.1.7 (2015-08-18) [x86_64-linux]
web_1 | [2015-11-17 11:52:22] INFO WEBrick::HTTPServer#start: pid=1 port=3000
I think this issue was fixed in docker-compose 1.5. You'll only get logs from the time to start the container.

Resources