TL DR: How do I change my docker-compose.yml
below so that one container can use the service of another through a custom (non-standard) port?
I have a fairly common setup: containers for a web application (Padrino [Ruby]), Postgres, Redis, and a queue structure (Sidekiq). The web application comes with a custom Dockerfile, other services come either from standard images (Postgres, Redis), or mount data from the web application (Sidekiq). They are connected to each other via 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 of the key points that should be noted here is that I expose container services to non-standard ports (9000-9002).
If I started the installation using docker-compose up
, the Redis and Postgres containers look fine, but the containers for the web application and Sidekiq fail because they cannot connect to Redis in redis:9002
. It is noteworthy that the same setup works if I use 6379 (standard Redis port) instead of 9002.
docker ps
also looks great afaik:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9148566c2509 redis "docker-entrypoint.sh" Less than a second ago Up About a minute 0.0.0.0:9002->6379/tcp rubydockerpadrino_redis_1 e6d47321c939 postgres:9.5 "/docker-entrypoint.s" Less than a second ago Up About a minute 0.0.0.0:9001->5432/tcp rubydockerpadrino_postgres_1
What's even more confusing: I can access the Redis container from the host through redis-cli -h localhost -p 9002 -n 0
, but the web application and Sidekiq containers cannot establish a connection.
I use this version of dockers on MacOS: Docker version 1.12.3, build 6b644ec, experimental
Any ideas what I'm doing wrong? I would appreciate how to start my installation.