Home > front end >  Centos 7 docker yum installation gets stuck
Centos 7 docker yum installation gets stuck

Time:11-08

When I am trying to build Dockerfile docker build -t agent . my build process gets stuck on yum installation process, and it goes further neither on my Linux nor Windows:

  yum -q install -y bash bzip2-devel ca-certificates curl epel-release gcc gcc-c   git gnutls gnutls-devel libffi-devel make ncurses-devel openssh-clients openssh-server openssl openssl-devel rsync readline-devel tar unzip wget zip zlib-devel temurin-11-jdk
Package bash-4.2.46-35.el7_9.x86_64 already installed and latest version
Package ca-certificates-2022.2.54-74.el7_9.noarch already installed and latest version
Package curl-7.29.0-59.el7_9.1.x86_64 already installed and latest version
Package 2:tar-1.26-35.el7.x86_64 already installed and latest version

Dockerfile code

FROM centos:7

RUN set -ex &&  echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' > /etc/nsswitch.conf

RUN set -ex && yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
RUN set -ex && yum -q install -y docker-ce docker-ce-cli containerd.io

# -- Install OS packages:
RUN set -ex && yum -q update -y && yum -q install -y \
    bash \
    bzip2-devel \
    ca-certificates \
    curl \
    epel-release \
    gcc \
    gcc-c   \
    git \
    gnutls \
    gnutls-devel \
    libffi-devel \
    make \
    ncurses-devel \
    openssh-clients \
    openssh-server \
    openssl \
    openssl-devel \
    rsync \
    readline-devel \
    tar \
    unzip \
    wget \
    zip \
    zlib-devel \
    temurin-11-jdk

I tried to build other centos images and it builds well, even tried Ubuntu and other random images. This problem is specific only in this Dockerfile

CodePudding user response:

You are hitting this bug (also see this pull request with the fix). Older versions of rpm (such as in CentOS 7) include code that attempts to set the CLOEXEC flag on all file descriptors. Because Docker sets a high limit on the number of files (1073741816), this process takes a ridiculously long time.

The simplest workaround -- if you're forced to use an older distribution like CentOS 7 -- is to reduce the limit before running yum:

FROM centos:7

RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' > /etc/nsswitch.conf

RUN yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
RUN ulimit -n 1024 && yum -q install -y docker-ce docker-ce-cli containerd.io

# -- Install OS packages:
RUN ulimit -n 1024 && yum -q update -y && yum -q install -y \
    bash \
    bzip2-devel \
    ca-certificates \
    curl \
    epel-release \
    gcc \
    gcc-c   \
    git \
    gnutls \
    gnutls-devel \
    libffi-devel \
    make \
    ncurses-devel \
    openssh-clients \
    openssh-server \
    openssl \
    openssl-devel \
    rsync \
    readline-devel \
    tar \
    unzip \
    wget \
    zip \
    zlib-devel \
    temurin-11-jdk

Using the above Dockerfile:

$ time docker build -t yumtest .
[...]
Successfully built e5ae777ff3ff
Successfully tagged yumtest:latest

real    1m2.668s
user    0m0.008s
sys     0m0.015s
  • Related