I use docker-compose to provide a development environment for developers using the tech stack ROR, postgres, redis, mongo. docker-compose build works successfully, but when I started docker-compose up , an error occurred.
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'
Below is the Dockerfile
# Base image. FROM atlashealth/ruby:2.2.1
Docker-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
I set the environment variable for postgres and redis host and port according to the output of the docker-compose run web env .
the output of the 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
configurations / sidekiq.yml
concurrency: 25 pidfile: ./tmp/pids/sidekiq.pid logfile: ./log/sidekiq.log queues: - default - [priority, 2] daemon: true
config / 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'] %>
configurations / Initializers / 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"] )