package installations are very slow in docker build

5,558

This is probably related to the ulimit for nofile.

You can check what your container get by running

docker run ubuntu:16.04 bash -c "ulimit -n"

Set this during build/run with

docker run --ulimit nofile=1024 ...
docker build --ulimit nofile=1024 ...

Or configure your docker daemon as described in the documentation.

I would recommend 1024 as a good starting point. Tweak to your personal needs.

https://docs.docker.com/engine/reference/commandline/run/#set-ulimits-in-container---ulimit

Note that there is a bug that preventes you from setting the default-ulimits in the daemon.json file prior to Docker 1.13. You need to use the --default-ulimits command line option when launching the daemon for docker versions prior to 1.13.

Share:
5,558
Rijad Rahim
Author by

Rijad Rahim

Updated on September 18, 2022

Comments

  • Rijad Rahim
    Rijad Rahim over 1 year

    I've created a 16.04 ubuntu in docker, but installing the packages taking too much time. working behind corporate proxy, can someone help me with it.

    tried in 14.04 version also, same speed. but the images are downloaded in seconds(72MB).

  • Anand
    Anand over 5 years
    did not work for me :(
  • gangefors
    gangefors over 5 years
    @Anand What is your ulimit in the container and what kind of issues are you seeing when setting the nofile ulimit? The issue I saw was that the time was increasing with each package during apt install until it took minutes for a package to be installed. If you are seeing something different the root cause might not be the ulimit.
  • Evgeny
    Evgeny about 5 years
    Ran into this issue on an AWS instance. I've tried raising ulimit, did not help much