turnbullpress / dockerbook-code

The code and configuration examples from The Docker Book (http://www.dockerbook.com)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

replica does not connect to primary using hostname

normoes opened this issue · comments

I built the redis cluster and used docker version 1.13 (newest kindle ebook edition).

project:
The redis_replica Dockerfile contains the line --slaveof redis-primary 6379 in order to connect to redis_primary.
You explicitly mention that hostnames may not contain underscores _ that's why you call it redis-primary instead of redis_primary which is the name of the image itself.

problem:
In my setup, the redis_replica container does not find redis_primary using the hostname redis-primary.
I had to change the line
--slaveof redis-primary 6379
to
--slaveof redis_primary 6379
using the container name redis_primary rather than the hostname redis-primary.

You mentioned some tiny bit about DNS, but nothing specifically.
Did you edit your host file or some container's host file anywhere, maybe I missed that point reading the book.

Do you have any advice?
Thanks.

The node application also uses the container's name:
host: process.env.REDIS_HOST || 'redis_primary',

Regards!

I have the same issue, i cannot connect on port 6379. I have double check my Dockerfile (from redis-base, primary and replica) and are identical as the book.

I did tried to change redis-primary to redis_primary on Dockerfile but on redis slave i get this error:

1:S 08 Mar 20:26:45.281 * The server is now ready to accept connections on port 6379
1:S 08 Mar 20:26:45.281 * Connecting to MASTER redis_primary:6379
1:S 08 Mar 20:26:45.282 * MASTER <-> SLAVE sync started
1:S 08 Mar 20:26:45.282 * Non blocking connect for SYNC fired the event.
1:S 08 Mar 20:26:45.282 # Error condition on socket for SYNC: Connection reset by peer
1:S 08 Mar 20:26:46.302 * Connecting to MASTER redis_primary:6379
1:S 08 Mar 20:26:46.303 * MASTER <-> SLAVE sync started
1:S 08 Mar 20:26:46.303 * Non blocking connect for SYNC fired the event.
1:S 08 Mar 20:26:46.303 # Error reply to PING from master: '-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect'

Thanks folks - I suspect something in the recent Docker release is weird here. I'll take a look.

@mistre833,
The curent release of the docker book does not contain the current code that can be found here.
Take a look at the redis_primary Dockerfile as well as the redis_replica Dockerfile.

They now both contain the option

protected mode no

when calling redis-server.

This is necessary due to the current version of redis, which is "more secure" by default :)

Thanks. That update is in an unreleased version of the book.

Did you also consider the original question regarding the hostname and container name?

Mhhhh i didnt look the source code here on github, i just see the code on website page.. here is the updated code.

Thanks for your help.

@normoes Replace all redis-replica or redis-primary with redis_replica and redis_primary respectively. It looks like Docker has changed the rules on what hostnames are supported. I'll update for the next edition of the book.