Wilson Ho
Wilson Ho

Reputation: 372

Can not start 2 cassandra containers on mac

I have a situation with cassandra container.

I have 2 docker-compse.yaml files in different folders.

docker-compose.yaml in folder 1

version: "3"
services:
  cassandra-cluster-node-1:
    image: cassandra:3.0
    container_name: cassandra-cluster-node-1
    hostname: cassandra-cluster-node-1
    ports:
      - '9142:9042'
      - '7199:7199'
      - '9160:9160'

docker-compose.yaml in folder 2

version: "3"
services:
  cassandra-cluster-node-2:
    image: cassandra:3.0
    container_name: cassandra-cluster-node-2
    hostname: cassandra-cluster-node-2
    ports:
      - '9242:9042'
      - '7299:7199'
      - '9260:9160'

I tried to up cassandra on folder 1, the system work well, after that I up cassandra on folder 2. But at this time, service cassandra on folder 1 is killed automatically. So I didn't understand with them, could you guys please, who have experiences with Docker can help me to explain this situation?

The error in cassandra_1 after I run cassandra_2

cassandra-cluster-node-1 exited with code 137

Thank you, I'm going to appreciate your help.

Upvotes: 2

Views: 1265

Answers (1)

Andreas Wederbrand
Andreas Wederbrand

Reputation: 40021

137 is out of memory error. Cassandra uses a lot of memory if started with default settings. By default it takes 1/4 of the system memory. For each instans. You can restrict the memory usage using environment variables (see my example further down)

Docker compose creates a network for each directory it runs under. With your setup the two nodes will never be able to find each other. This is the output from my test, your files are put into two directories; cass1 and cass1

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
dbe9cafe0af3        bridge              bridge              local
70cf3d77a7fc        cass1_default       bridge              local
41af3e02e247        cass2_default       bridge              local
21ac366b7a31        host                host                local
0787afb9aeeb        none                null                local

You can see the two networks cass1_default and cass2_default. So the two nodes will not find each other.

If you want them to find each other you have to give the first one as a seed to second one, and they have to be in the same network (same docker-compose file)

version: "3"
services:
  cassandra-cluster-node-1:
    image: cassandra:3.0
    container_name: cassandra-cluster-node-1
    hostname: cassandra-cluster-node-1
    environment:
      - "MAX_HEAP_SIZE=1G"
      - "HEAP_NEWSIZE=256M"
    ports:
      - '9142:9042'
      - '7199:7199'
      - '9160:9160'

  cassandra-cluster-node-2:
    image: cassandra:3.0
    container_name: cassandra-cluster-node-2
    hostname: cassandra-cluster-node-2
    environment:
      - "MAX_HEAP_SIZE=1G"
      - "HEAP_NEWSIZE=256M"
      - "CASSANDRA_SEEDS=cassandra-cluster-node-1"
    ports:
      - '9242:9042'
      - '7299:7199'
      - '9260:9160'
    depends_on:
      - cassandra-cluster-node-1

Upvotes: 5

Related Questions