Unable to start cassandra : Unable to lock JVM memory (ENOMEM)

Viewed 543

I am trying to start a cassandra container using docker-compose . I am issueing the following command from my macbook terminal.

docker-compose -f src/main/docker/cassandra.yml up 

my cassandra.yml file is below

version: '2'
services:
    primecast-cassandra:
        image: cassandra:3.9
        # volumes:
        #     - ~/volumes/jhipster/primecast/cassandra/:/var/lib/cassandra/data
        ports:
            - 7000:7000
            - 7001:7001
            - 7199:7199
            - 9042:9042
            - 9160:9160
    primecast-cassandra-migration:
        extends:
            file: cassandra-migration.yml
            service: primecast-cassandra-migration
        environment:
            - CREATE_KEYSPACE_SCRIPT=create-keyspace.cql

However when i run the docker-compose command to start the cassandra services i get some warning on the terminal & eventually it stops.

    primecast-cassandra_1            | WARN  14:33:45 Unable to lock JVM memory (ENOMEM). 

This can result in part of the JVM being swapped out, especially with mmapped I/O enabled.  Increase RLIMIT_MEMLOCK or run Cassandra as root.

appreciate if you can help thank you

1 Answers

Essentially, this message is telling you that you need to specify memlock unlimited for the Linux system resource limit on the locked-in memory for a specific user. As per the documentation on recommended production settings, the normal (non-Docker) way to solve for this was to adjust the /etc/security/limits.conf file (or equivalent) as such:

cassandra - memlock unlimited

In the above example, cassandra is the user that Cassandra is running under. If you're running Cassandra as another user, you'll need to either change that accordingly or just use asterisk (*) to enforce that setting for all users. Ex:

* - memlock unlimited

In this case with Docker Compose v2, ulimits should be a valid entry under the service configuration. Set memlock to -1 so that both the soft and hard limits are "unlimited":

primecast-cassandra:
    image: cassandra:3.9
    ulimits:
        memlock: -1
    ports:
Related