2015-10-08 8 views
5

私はtech-stack ROR、postgres、redis、mongoを開発者に提供するためにdocker-composeを使用しています。 docker-compose buildは正常に動作していますが、エラーが発生した後にdocker-compose upを実行しました。 Dockerfile/home/web/.gem/ruby/2.2.0/gems/redis-3.2.1/lib/redis/connection/ruby.rb:152:in'getaddrinfo ':getaddrinfo:名前またはサービスが不明(SocketError)

ある
# Base image. 
FROM atlashealth/ruby:2.2.1 

# System dependencies for gems. 
#RUN apt-get update 
#RUN apt-get install -y --no-install-recommends libmysqlclient-dev 
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev 

# Add 'web' user which will run the application. 
RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos "" 

# Add directory where all application code will live and own it by the web user. 
RUN mkdir /app 
RUN chown -R web:web /app 

# Install gems separately here to take advantage of container caching of `bundle install`. 
# Also, ensure that gems are installed as the web user and not system-wide so that we can run 
# `fig web bundle install` and the web user will have permissions to update the shared Gemfile.lock. 
ADD Gemfile /app/ 
ADD Gemfile.lock /app/ 
RUN chown -R web:web /app 
USER web 
ENV HOME /home/web 
ENV PATH $PATH:/home/web/.gem/ruby/2.2.0/bin 
ENV GEM_HOME /home/web/.gem/ruby/2.2.0 
ENV GEM_PATH $GEM_HOME 
RUN gem install --user-install bundler 
WORKDIR /app/ 
RUN bundle install 
USER root 

# Add the whole application source to the image and own it all by web:web. 
# Note: this is overwritten in development because fig mounts a shared volume at /app. 
ADD . /app/ 
RUN chown -R web:web /app 

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

# Default command to run when this container is run. 
USER web 
WORKDIR /app/ 
CMD ["bundle", "exec", "rails", "server"] 

ドッキングウィンドウ-compose.yml

db: 
    image: postgres 
    ports: 
    - "5432" 

redis: 
    image: redis 
    ports: 
    - "6379" 

sidekiq: 
    build: . 
    command: bundle exec sidekiq 
    links: 
    - db 
    - redis 

web: 
    build: . 
    command: bundle exec rails s -b 0.0.0.0 
    volumes: 
    - .:/app 
    ports: 
    - "3000:3000" 
    links: 
    - db 
    - redis 

web_1 | => Booting Thin 
web_1 | => Rails 4.2.3 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 | /home/web/.gem/ruby/2.2.0/gems/redis-3.2.1/lib/redis/connection/ruby.rb:152:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError) 
web_1 | from /home/web/.gem/ruby/2.2.0/gems/redis-3.2.1/lib/redis/connection/ruby.rb:152:in `connect' 
web_1 | from /home/web/.gem/ruby/2.2.0/gems/redis-3.2.1/lib/redis/connection/ruby.rb:211:in `connect' 
web_1 | from /home/web/.gem/ruby/2.2.0/gems/redis-3.2.1/lib/redis/client.rb:322:in `establish_connection' 
web_1 | from /home/web/.gem/ruby/2.2.0/gems/redis-3.2.1/lib/redis/client.rb:94:in `block in connect' 
web_1 | from /home/web/.gem/ruby/2.2.0/gems/redis-3.2.1/lib/redis/client.rb:279:in `with_reconnect' 

私はpostgresのとRedisのホストの設定環境変数を持っており、ポートacc docker-compose run web envコマンドの出力に向かう。

コマンドの出力docker-compose run web cat /etc/hosts

Starting xyz_db_1... 
Starting xyz_redis_1... 
172.17.0.32 2b231a706e7b 
127.0.0.1 localhost 
::1 localhost ip6-localhost ip6-loopback 
fe00::0 ip6-localnet 
ff00::0 ip6-mcastprefix 
ff02::1 ip6-allnodes 
ff02::2 ip6-allrouters 
172.17.0.31 redis 799b65ac89cd xyz_redis_1 
172.17.0.31 redis_1 799b65ac89cd xyz_redis_1 
172.17.0.30 db 0bd898e19822 xyz_db_1 
172.17.0.30 db_1 0bd898e19822 xyz_db_1 
172.17.0.30 xyz_db_1 0bd898e19822 
172.17.0.31 xyz_redis_1 799b65ac89cd 

設定/ sidekiq.yml

concurrency: 25 
pidfile: ./tmp/pids/sidekiq.pid 
logfile: ./log/sidekiq.log 
queues: 
    - default 
    - [priority, 2] 
daemon: true 

設定/ APP-config.yml

default: &default 
    redis_host: <%= ENV['XYZ_REDIS_1_PORT_6379_TCP_ADDR'] %> 
    redis_port: <%= ENV ['XYZ_REDIS_1_PORT_6379_TCP_PORT'] %> 
    redis_namespace: 'RAILS_CACHE' 

development: 
    <<: *default 
    redis_host: <%= ENV['XYZ_REDIS_1_PORT_6379_TCP_ADDR'] %> 
    redis_port: <%= ENV['XYZ_REDIS_1_PORT_6379_TCP_PORT'] %> 

設定/初期化子/ redis.rb

# global variable to access Redis cache 
# Requirement: Redis server should be up and running 
# at below specified host and port 
$redis = Redis.new(
    :host => APP_CONFIG["redis_host"], 
    :port => APP_CONFIG["redis_port"] 
) 
+0

を。私は示唆したい:環境変数を使用しないでください。/ etc/hostsによって提供されるホスト名を使用してください( 'docker-compose run web cat/etc/hosts'をチェックアウトしてください)。例: 'redis_1'ではなく' redis'を使用してください。私は、ルビとホスト名にアンダースコアが付いている問題があることを覚えていると思います。 – dnephin

+0

@dnephin、編集を参照してください。私は 'docker-compose run web cat/etc/hosts'の出力を追加しました –

+0

私は誤解していますが、あなたのアプリのredisが正しく設定されていないようです。あなたはredis gemを単独で使っているのですか、sidekiq/activejobのようなライブラリを使っていますか? – christoshrousis

答えて

1

REDIS_URL環境変数がSidekiqとRedisの宝石の両方にRedisのURLを渡すために使用することができます。

この環境変数は次のようにdocker-compose.ymlで設定することができます。SidekiqとRedisの宝石は、デフォルトでREDIS_URLを使用すると

db: 
    image: postgres 
    ports: 
    - "5432" 

redis: 
    image: redis 
    ports: 
    - "6379" 

web: 
    build: . 
    command: bundle exec rails s -b 0.0.0.0 
    volumes: 
    - .:/app 
    ports: 
    - "3000:3000" 
    links: 
    - db 
    - redis 
    environment: 
    REDIS_URL: "redis://redis:6379" 

、また、あなたはこのデフォルトの動作をオーバーライドしていないことを確認する必要があります設定ファイル。あなたはもうファイルconfig/initializers/redis.rbを必要としない、とあなたのconfig/app-config.ymlは、あなたの名前空間を含める必要があります。それは、アプリケーションの詳細を知らなくても、ここで何が起こっているかを言うのは難しいです

default: &default 
    redis_namespace: 'RAILS_CACHE' 

development: 
    <<: *default 
+0

違いはありません。同じエラーが発生する –

+0

'Sidekiq' ou' R​​edis'の設定をオーバーライドしている設定ファイルまたはイニシャライザファイルがありますか?これは 'REDIS_URL'変数がなぜオーバーライドされるのかを説明します。 – haradwaith

+0

redisとsidekiqの設定については、編集を参照してください。 –

関連する問題