softshipper
softshipper

Reputation: 34071

Where to public zookeeper hosts?

I have following scenario that looks as following:

enter image description here

As you can see, I have two docker hosts installed, Dockerhost1 and Dockerhost2. Inside both hosts, 2 Zookeeper container are running.

I want, that all Zookeeper containers to know each other, because I want to build a cluster environment.

Following networks are available:

Dockerizer@docker1:~$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
dbf91cc26912        bridge              bridge              local
57f38c4c93ad        host                host                local
5d54f5ce807e        none                null                local

My questions are:

In which network do I have to run the Zookeeper containers? I would guess on host network?

To run two containers on the hosts, I would create a compose file, that contains:

version: '3.1'

services:
    zoo1:
        image: zookeeper
        restart: always
        hostname: zoo1
        ports:
            - 2181:2181
        environment:
            ZOO_MY_ID: 1
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888

    zoo2:
        image: zookeeper
        restart: always
        hostname: zoo2
        ports:
            - 2182:2181
        environment:
            ZOO_MY_ID: 2
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888  

How to configure the network, that they know all each other?

It is recommended to install docker swarm, to make it as a cluster?

Upvotes: 0

Views: 748

Answers (1)

BMitch
BMitch

Reputation: 263617

I'd likely implement swarm mode, not for the swarm scheduling and managing the containers as a scaled service, but for the included overlay networking. You can setup your own k/v store and use that for overlay networking, but it's much easier on host 1 to run:

docker swarm init

and then run the output join command on host 2.

Then you can create an overlay network that's attachable and spans both hosts:

docker network create -d overlay --attachable zookeeper

Attachable lets you also use the network outside of swarm services. You just add that as an external network in your compose file:

version: '3.1'

networks:
  zookeeper:
    external: true

services:
    zoo1:
        image: zookeeper
        restart: always
        hostname: zoo1
        networks:
            - zookeeper
        ports:
            - 2181:2181
        environment:
            ZOO_MY_ID: 1
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888

    zoo2:
        image: zookeeper
        restart: always
        hostname: zoo2
        networks:
            - zookeeper
        ports:
            - 2182:2181
        environment:
            ZOO_MY_ID: 2
            ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 

Upvotes: 1

Related Questions