docker エラー「library initialization failed – unable to allocate file descriptor table – out of memory」が発生した場合の対処法

docker エラー「library initialization failed – unable to allocate file descriptor table – out of memory」が発生した場合の対処法

docker-compose.ymlを作成して「docker-compose up」実行時に、「library initialization failed – unable to allocate file descriptor table – out of memory」が発生した場合の対処法を記述してます。

環境

  • OS CentOS Stream release 9
  • docker 20.10.21

エラー全文

対象の「docker-compose.yml」は、以下となります。

version: '2'
services:
    app:
        image: koda/docker-knowledge
        #build: .
        volumes:
            - ./volumes/knowledge:/root/.knowledge
        ports:
            - "8080:8080"
        restart: always
        depends_on:
            - "db"
    db:
        image: postgres:9
        environment:
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=admin123
            - POSTGRES_DB=knowledge_production
        volumes:
            #- ./volumes/initdb:/docker-entrypoint-initdb.d
            - ./volumes/postgres/data:/var/lib/postgresql/data
        restart: always

エラー全文

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

対処法

自分の場合は「ulimits」値を追加で記述することで改善しました。

version: '2'
services:
    app:
        image: koda/docker-knowledge
        #build: .
        volumes:
            - ./volumes/knowledge:/root/.knowledge
        ulimits:
          nofile:
            soft: 65536
            hard: 65536
        ports:
            - "8081:8080"
        restart: always
        depends_on:
            - "db"
    db:
        image: postgres:9
        environment:
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=admin123
            - POSTGRES_DB=knowledge_production
        volumes:
            #- ./volumes/initdb:/docker-entrypoint-initdb.d
            - ./volumes/postgres/data:/var/lib/postgresql/data
        restart: always