ruby - docker-compose: connection refused between containers, but service accessible from host -
tl;dr: how have change below docker-compose.yml
in order allow 1 container use service of on custom (non-standard) port?
i have pretty common setup: containers web app (padrino [ruby]), postgres, redis, , queueing framework (sidekiq). web app comes custom dockerfile, remaining services come either standard images (postgres, redis), or mount data web app (sidekiq). ties via following docker-compose.yml
:
version: '2' services: web: build: . command: 'bundle exec puma -c config/puma.rb' volumes: - .:/myapp ports: - "9000:3000" depends_on: - postgres - redis sidekiq: build: . command: 'bundle exec sidekiq -c config/sidekiq.yml -r ./config/boot.rb' volumes: - .:/myapp depends_on: - postgres - redis postgres: image: postgres:9.5 environment: postgres_user: my-postgres-user postgres_password: my-postgres-pass ports: - '9001:5432' volumes: - 'postgres:/var/lib/postgresql/data' redis: image: redis ports: - '9002:6379' volumes: - 'redis:/var/lib/redis/data' volumes: redis: postgres:
one key point notice here exposing containers services on non-standard ports (9000-9002).
if start setup docker-compose up
, redis , postgres containers come fine, containers web app , sidekiq fail since can't connect redis @ redis:9002
. remarkably enough, same setup works if use 6379 (the standard redis port) instead of 9002.
docker ps
looks fine afaik:
container id image command created status ports names 9148566c2509 redis "docker-entrypoint.sh" less second ago minute 0.0.0.0:9002->6379/tcp rubydockerpadrino_redis_1 e6d47321c939 postgres:9.5 "/docker-entrypoint.s" less second ago minute 0.0.0.0:9001->5432/tcp rubydockerpadrino_postgres_1
what's more confusing: can access redis container from host via redis-cli -h localhost -p 9002 -n 0
, web app , sidekiq containers fail establish connection.
i using docker version on macos: docker version 1.12.3, build 6b644ec, experimental
any ideas doing wrong? i'd appreciate hint how setup running.
when bind ports '9002:6379'
you're telling docker forward traffic localhost:9002
-> redis:6379
. that's why works host machine:
redis-cli -h localhost -p 9002 -n 0
however, when containers talk each other, connected same network default (the docker bridge or docker0
). default, containers can communicate each other freely on network, without needing ports opened. within network, redis
container listening traffic on it's usual port (6379
), host isn't involved @ all. that's why container container communication works on 6379
.
Comments
Post a Comment