the-witcher-knight
the-witcher-knight

Reputation: 620

Docker - library initialization failed - unable to allocate file descriptor table - out of memory

I have been try to run Zookeeper and Kafka on Docker container. I got a lot of errors [error occurred during error reporting , id 0xb] and [Too many errors, abort] in my terminal. And then library initialization failed - unable to allocate file descriptor table - out of memory.

I use the following docker-compose.yml file

version: "3.8"
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:5.5.4
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
  kafka:
    image: confluentinc/cp-kafka:5.5.4
    # If you want to expose these ports outside your dev PC,
    # remove the "127.0.0.1:" prefix
    ports:
      - 127.0.0.1:9092:9092
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

Upvotes: 17

Views: 29438

Answers (5)

the-witcher-knight
the-witcher-knight

Reputation: 620

This problem is caused by having too many file handles available to the program. It increases its soft limit on files to the maximum available, then attempts to allocate memory for each of those file handles. For some systems, with high limits, this causes insufficent memory.

It can be fixed by overriding the command arguments of ExecStart in docker.service

sudo systemctl edit docker

and then enter

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --default-ulimit nofile=65536:65536 -H fd://

Save and run sudo systemctl daemon-reload and sudo systemctl restart docker.

Upvotes: 30

david n
david n

Reputation: 41

I did try most of the solutions presented above this, without success. Finally, I started Jenkins container by adding --ulimit nofile=8096:8096 in the docker run command.

For example:
docker run -d --ulimit nofile=8096:8096 -p 8089:8080 -v ~/jenkins_home/jenkins:/var/jenkins_home --name jenkins jenkins:2.60.1

Now the container is running successfully.

Upvotes: 3

Sourav Ahmed
Sourav Ahmed

Reputation: 26

version: "3.9"
networks:
  nrixmw:
    driver: bridge
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:latest
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    hostname: zookeeper
    ports:
      - 2181:2181
    environment:
      ZOOKEEPER_CLIENT_PORT: '2181'
      ZOOKEEPER_TICK_TIME: '2000'
    networks:
      - nrixmw
  broker:
    image: confluentinc/cp-kafka:5.4.2
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    hostname: broker
    depends_on:
      - zookeeper
    ports:
      - 29092:29092
      - 9092:9092
      - 9101:9101
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
      # KAFKA_ADVERTISED_HOST_NAME: 'broker'
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_LISTENERS: 'PLAINTEXT://:29092,PLAINTEXT_HOST://:9092'
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
      KAFKA_DELETE_TOPIC_ENABLE: 'true'
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
    networks:
      - nrixmw
    mem_limit: 6g
    restart: always
  schema-registry:
    image: confluentinc/cp-schema-registry:5.5.1
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    depends_on:
      - zookeeper
      - broker
    ports:
      - "8081:8081"
    environment:
      SCHEMA_REGISTRY_HOST_NAME: schema-registry
      SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: 'zookeeper:2181'
    networks:
      - nrixmw

This is how i do it, hope fully this will solve your err. My system conf - Linux sourav-tuf 5.15.114-2-MANJARO #1 SMP PREEMPT Sun Jun 4 10:32:43 UTC 2023 x86_64 GNU/Linux (24g ram)

i have a mint machine, where i dont need all these ulimits, and its still working, this is arch os prob maybe. not sure.

Upvotes: 0

donmaro
donmaro

Reputation: 351

Try to add ulimits configuration to zookeeper like that

---
version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "2181:2181"

Upvotes: 23

Felipe Tapia
Felipe Tapia

Reputation: 379

I think that your kafka broker needs to have a dependency from your zookeper. This works for me:

---
version: '2'
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:6.2.0
    hostname: zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000

  broker:
    image: confluentinc/cp-server:6.2.0
    hostname: broker
    container_name: broker
    depends_on:
      - zookeeper
    ports:
      - "9092:9092"
      - "9101:9101"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_CONFLUENT_BALANCER_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_JMX_PORT: 9101
      KAFKA_JMX_HOSTNAME: localhost
      CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:29092
      CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
      CONFLUENT_METRICS_ENABLE: 'true'
      CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'

Upvotes: 0

Related Questions