when I try to configure debug in vscode for a Ruby on Rails app with docker, follow my Dockerfile:
FROM ruby:2.6.5
# add nodejs and yarn dependencies for the frontend
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# Instala nossas dependencias
RUN apt-get update && apt-get install -qq -y --no-install-recommends \
nodejs yarn build-essential libpq-dev imagemagick git-all nano
# Instalar bundler
RUN gem install bundler
# Seta nosso path
ENV INSTALL_PATH /onebitexchange
# Cria nosso diretório
RUN mkdir -p $INSTALL_PATH
# Seta o nosso path como o diretório principal
WORKDIR $INSTALL_PATH
# Copia o nosso Gemfile para dentro do container
COPY Gemfile ./
# Seta o path para as Gems
ENV BUNDLE_PATH /gems
# Copia nosso código para dentro do container
COPY . .
My docker-compose.yml:
version: "3.8"
services:
db:
image: "postgres:12.2"
environment:
- POSTGRES_PASSWORD=postgres
volumes:
- postgres:/var/lib/postgresql/data
app:
build: .
command: bash start.sh
ports:
- "3000:3000"
- "1234:1234"
environment:
- DB_PASSWORD=postgres
volumes:
- .:/onebitexchange
- gems:/gems
depends_on:
- db
volumes:
postgres:
gems:
My start.sh:
# Instala as Gems
bundle check || bundle install
# Roda nosso servidor
# bundle exec puma -C config/puma.rb
bundle exec rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- /onebitexchange/bin/rails s -b 0.0.0.0 -e development
my launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Docker",
"type": "Ruby",
"request": "attach",
"remotePort": "1234",
"remoteHost": "127.0.0.1",
"remoteWorkspaceRoot": "/onebitexchange",
"cwd": "${workspaceRoot}",
"showDebuggerOutput": true
}
]
}
my project work fine if I start without debug (bundle exec puma -C config/puma.rb), but when I try start with debug container I get the follow messages ( no problems yet):
Successfully built c60b5fc8b26a
Successfully tagged onebit_exchange_app:latest
Starting onebit_exchange_db_1 ... done
Recreating onebit_exchange_app_1 ... done
Attaching to onebit_exchange_db_1, onebit_exchange_app_1
db_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2020-05-19 16:38:29.734 UTC [1] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-05-19 16:38:29.734 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-05-19 16:38:29.734 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-05-19 16:38:29.745 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-05-19 16:38:29.784 UTC [28] LOG: database system was shut down at 2020-05-19 14:38:39 UTC
db_1 | 2020-05-19 16:38:29.791 UTC [1] LOG: database system is ready to accept connections
app_1 | The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
app_1 | The Gemfile's dependencies are satisfied
app_1 | start.sh: line 3: $'\342\200\213': command not found
app_1 | Fast Debugger (ruby-debug-ide 0.7.2, debase 0.2.4.1, file filtering is supported) listens on 0.0.0.0:1234
but when I start debug in vscode:
app_1 | => Booting Puma
app_1 | => Rails 6.0.2.2 application starting in development
app_1 | => Run `rails server --help` for more startup options
app_1 | A server is already running. Check /onebitexchange/tmp/pids/server.pid.
app_1 | Exiting
onebit_exchange_app_1 exited with code 1
Thank you
Looks like you have some funny encoding on line 3 of your start.sh file that isn't being interpreted as a comment, which is likely causing the commented line to actually start a server.
When the bundle exec rdebug-ide --host 0.0.0.0 --port 1234... command executes, it throws the 'port in use' error because there is already a server running on port 1234 from the first command.
If you remove the commented-out lines you should be good to go.
Related
I am trying to run a docker-compose file but there is a error that i can´t solve by myself.
I don´t know how to delete the info in the directory that the error specifies, can anyone help??
My dockerfile content:
FROM python:3
RUN apt-get update -y; apt-get upgrade -y
RUN yes | apt install build-essential portaudio19-dev
RUN python -m pip install --upgrade pip
COPY ./dependecies/requirements.txt .
COPY . ./usr/src/app
WORKDIR /usr/src/app
RUN pip install --upgrade pip
RUN pip install torch
RUN pip install -r requirements.txt
CMD ["python", "main"]
My docker-compose content:
version: '3.9'
services:
python_app:
build: ./facadeback/
container_name: python-backend
volumes:
- ./facadeback:usr/src/app
command: sh -c "sleep 10s"
depends_on:
- mysql_db
mysql_db:
image: mysql
container_name: mysql-bd
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1234
volumes:
- ./facadeadd/bd/:var/lib/mysql
ports:
- '3306:3306'
The error log is this when i try to run docker-compose up:
[+] Running 2/0
- Container mysql-bd Created
- Container python-backend Created
Attaching to mysql-bd, python-backend
mysql-bd | 2022-11-24 10:37:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
mysql-bd | 2022-11-24 10:37:43+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-bd | 2022-11-24 10:37:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
mysql-bd | 2022-11-24 10:37:43+00:00 [Note] [Entrypoint]: Initializing database files
mysql-bd | 2022-11-24T10:37:43.952783Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql-bd | 2022-11-24T10:37:43.953374Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 80
mysql-bd | 2022-11-24T10:37:43.956544Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
mysql-bd | 2022-11-24T10:37:43.956550Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
mysql-bd | 2022-11-24T10:37:43.956624Z 0 [ERROR] [MY-010119] [Server] Aborting
mysql-bd | 2022-11-24T10:37:43.956756Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL.
mysql-bd exited with code 1
I have a Docker installation that I would like to start with docker compose up (and not have to run 2 extra ttys ) so I added a Procfile.dev looking like this
web: bin/rails server -p 3000 -b '0.0.0.0'
js: yarn build_js --watch
css: yarn build_css --watch
The output is, however, less than enjoyable
√ mindling % docker compose up
[+] Running 3/0
⠿ Container mindling_redis Running 0.0s
⠿ Container mindling_db Running 0.0s
⠿ Container mindling_mindling_1 Created 0.0s
Attaching to mindling_db, mindling_1, mindling_redis
mindling_1 | 19:54:04 web.1 | started with pid 16
mindling_1 | 19:54:04 js.1 | started with pid 19
mindling_1 | 19:54:04 css.1 | started with pid 22
mindling_1 | 19:54:06 css.1 | yarn run v1.22.17
mindling_1 | 19:54:06 js.1 | yarn run v1.22.17
mindling_1 | 19:54:06 js.1 | $ esbuild app/javascript/*.* --bundle --outdir=app/assets/builds --watch
mindling_1 | 19:54:06 css.1 | $ tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --watch
mindling_1 | 19:54:08 js.1 | Done in 2.02s.
mindling_1 | 19:54:08 js.1 | exited with code 0
mindling_1 | 19:54:08 system | sending SIGTERM to all processes
mindling_1 | 19:54:08 web.1 | terminated by SIGTERM
mindling_1 | 19:54:09 css.1 | terminated by SIGTERM
mindling_1 exited with code 0
I've tried running a Bash in the application container - and calling the Procfile in a tty by itself looks more or less like this:
root#facfb249dc6b:/app# foreman start -f Procfile.dev
20:11:45 web.1 | started with pid 12
20:11:45 js.1 | started with pid 15
20:11:45 css.1 | started with pid 18
20:11:48 css.1 | yarn run v1.22.17
20:11:48 js.1 | yarn run v1.22.17
20:11:48 css.1 | $ tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --watch
20:11:49 js.1 | $ esbuild app/javascript/*.* --bundle --outdir=app/assets/builds --watch
20:11:50 js.1 | [watch] build finished, watching for changes...
20:11:53 web.1 | => Booting Puma
20:11:53 web.1 | => Rails 7.0.0 application starting in development
20:11:53 web.1 | => Run `bin/rails server --help` for more startup options
20:11:57 web.1 | Puma starting in single mode...
20:11:57 web.1 | * Puma version: 5.5.2 (ruby 3.0.3-p157) ("Zawgyi")
20:11:57 web.1 | * Min threads: 5
20:11:57 web.1 | * Max threads: 5
20:11:57 web.1 | * Environment: development
20:11:57 web.1 | * PID: 22
20:11:57 web.1 | * Listening on http://0.0.0.0:3000
20:11:57 web.1 | Use Ctrl-C to stop
20:11:58 css.1 |
20:11:58 css.1 | Rebuilding...
20:11:59 css.1 | Done in 1066ms.
^C20:13:23 system | SIGINT received, starting shutdown
20:13:23 web.1 | - Gracefully stopping, waiting for requests to finish
20:13:23 web.1 | === puma shutdown: 2021-12-22 20:13:23 +0000 ===
20:13:23 web.1 | - Goodbye!
20:13:23 web.1 | Exiting
20:13:24 system | sending SIGTERM to all processes
20:13:25 web.1 | terminated by SIGINT
20:13:25 js.1 | terminated by SIGINT
20:13:25 css.1 | terminated by SIGINT
root#facfb249dc6b:/app#
What is going on? It works when doing it 'by hand' but if I let docker-compose rip the processes somehow terminates!?!
I have isolated the issue to the build_css script in package.json (or at least it does keep going if I comment that line in the Procfile.dev)
All the 'dirty linen'
My package.json looks like this
{
...8<...
"scripts": {
"build_js": "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds",
"build_css": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css"
},
...8<...
}
My containers are exceptionally boring, looking like almost everybody else's:
FROM ruby:3.0.3
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y nodejs yarn
WORKDIR /app
COPY src/Gemfile /app/Gemfile
COPY src/Gemfile.lock /app/Gemfile.lock
RUN gem install bundler foreman && bundle install
EXPOSE 3000
ENTRYPOINT [ "entrypoint.sh" ]
version: "3.9"
db:
build: mysql
image: mindling_db
container_name: mindling_db
command: [ "--default-authentication-plugin=mysql_native_password" ]
ports:
- "3306:3306"
volumes:
- ~/src/mysql_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: mindling_development
mindling:
platform: linux/x86_64
build: .
volumes:
- ./src:/app
ports:
- "3000:3000"
depends_on:
- db
and finally my entrypoint.sh
#!/usr/bin/env bash
rm -rf /app/tmp/pids/server.pid
foreman start -f Procfile.dev
Allow me to give credit to they who deserve it!! The correct answer was provided by earlopain in this issue on rails/rails
It's actually an almost embarrassingly easy fix - once you know it :)
Add tty: true to your docker-compose.yml - like this
mindling:
platform: linux/x86_64
build: .
tty: true
volumes:
- ./src:/app
ports:
- "3000:3000"
depends_on:
- db
Thanks Earlopain & #walt_die, you saved my day. Writing this answer because I had a bit of explanation which didn't fit in the comment.
Just like yours, when trying to run rails in docker using docker-compose the problem I was facing was that CMD bin/dev in dockerfile was constantly crashing, although it worked when ran manually via bash.
The issue was not with tailwindcss but esbuild instead. This line js: yarn build --watch in Procfile.dev was failing because it runs esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=assets under the hood, and as mentioned by evanw in esbuild issue esbuild exits when stdin is closed.
So, the solution of adding tty: true to docker-compose.yml as above works.
Alternatively, one can also remove/comment out this line js: yarn build --watch from Procfile.dev works. But this won't compile the JS changes. So, one can jump into bash of the running container and manually run yarn build --watch
I'm trying to get a Rails 6 application to run in Docker. When the command rails server is executed from the dockerfile, I get an error.
remote: web_1_a59d968487d2 | warning Integrity check: System parameters don't match
remote: web_1_a59d968487d2 | error Integrity check failed
remote: web_1_a59d968487d2 | error Found 1 errors.
remote: web_1_a59d968487d2 |
remote: web_1_a59d968487d2 |
remote: web_1_a59d968487d2 | ========================================
remote: web_1_a59d968487d2 | Your Yarn packages are out of date!
remote: web_1_a59d968487d2 | Please run `yarn install --check-files` to update.
remote: web_1_a59d968487d2 | ========================================
remote: web_1_a59d968487d2 |
remote: web_1_a59d968487d2 |
remote: web_1_a59d968487d2 | To disable this check, please change `check_yarn_integrity`
remote: web_1_a59d968487d2 | to `false` in your webpacker config file (config/webpacker.yml).
remote: web_1_a59d968487d2 |
remote: web_1_a59d968487d2 |
remote: web_1_a59d968487d2 | yarn check v1.16.0
remote: web_1_a59d968487d2 | info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.
In my config/webpacker.yml file I have this line:
development:
<<: *default
check_yarn_integrity: false
In my config/environments/development.rb:
config.webpacker.check_yarn_integrity = false
I am also building my node_modules as part of the docker setup (Dockerfile):
FROM ruby:2.6.3
RUN apt-get update && apt-get install apt-transport-https
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y nodejs yarn
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
RUN rm -Rf node_modules/
RUN rm yarn.lock
RUN yarn install
ENV RAILS_ENV=development
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
Running docker-compose run web rails s -b 0.0.0.0 works.
Running docker-compose up --build web returns the error.
You can compare your Dockerfile+docker-compose.yml with this one and see if there is nay difference (like using RUN yarn install --check-files) which would make the error message disappear.
Another example (Dockerfile+docker-compose.yml) is used in "Running a Rails app with Webpacker and Docker" from Dirk de Kok
In both instances, the application is started with docker-compose up.
And they have followed, as you have, the recommendations of rails/webpacker issue 1568 (regarding config.webpacker.check_yarn_integrity = false in config/environments/development.rb)
It worked today. No code was changed, it just decided to work. I tried running docker-compose run web rm -rf / to start over, but it ignored that command then started working. C'est la vie. #vonc thanks for the effort, I'll reward you.
Edit: It returned. This time I fixed it using
docker rm $(docker ps -a -q)
Warning: This destroys all your containers. Do not use this if you have data inside your volumes.
The cause of the problem was experimenting with creating a Dockerfile and the compose was not clearing out a layer of the volume. docker-compose run is different than docker-compose up because run creates a new layer on top of the docker volume to execute the command, essentially creating a new container. Docker itself was failing to apply the changes to an old layer.
making config.webpacker.check_yarn_integrity = false is not a good idea.
It occurs due to version incompatibility.
try
rails webpacker:install
It should solve your problem.
if not try
$ rm yarn.lock
$ yarn cache clean
$ yarn install
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.
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