Answers: <p>The following command works, cobbled together from friendly advice and additional googling based on that input:</p>
  <pre><code>podman build --ulimit=nofile=131072:1048576 [other arguments here]
  </code></pre>
  <p>The latest releases of <code>podman</code> accept <code>--ulimit=host</code>, which is convenient if you want the same policy, but 3.4.4 does not, and in any case <code>--ulimit=host</code> works only for <code>podman create</code> and <code>podman run</code>. For <code>podman build</code> specifying limit names is a requirement.</p>
  <p>For the file descriptor limit the proper name is <code>nofiles</code>. The
  <a href="https://docs.podman.io/en/v4.4/markdown/podman-build.1.html#ulimit-type-soft-limit-hard-limit" rel="nofollow noreferrer">podman documentation for version 4.4</a> describes additional valid limit names.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-08-17T17:29:35.610Z
Answers: 2024-04-20T22:39:42.300Z
Answers: 2024-04-20T22:39:42.300Z
Answers: Tom Boutell
Answers: <p>To permanently raise the default ulimit, it's now possible to edit <code>/etc/containers/containers.conf</code> (or the same file at various other locations; see <a href="https://manned.org/man/containers.conf" rel="nofollow noreferrer"><code>man containers.conf</code></a>):</p>
  <p>Something like this:</p>
  <pre><code>[containers]
  default_ulimits = [
    &quot;nofile=16384:524288&quot;,
  ]
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-09-12T10:04:04.183Z
Answers: 2024-09-12T10:04:04.183Z
Answers: cyqsimon
Body: <p>I'm running podman 3.4.4 on Ubuntu 22.04 LTS server.</p>
  <p>I have been having <code>podman build</code> issues that are not reproducible if I do those steps after the container build using <code>podman run</code>.</p>
  <p>Eventually I traced it to this: the limits given to processes in <code>podman build</code> are completely different. Here's a sample Dockerfile:</p>
  <pre><code>FROM node:14-bullseye
  WORKDIR /app
  RUN echo &quot;clear cache 1&quot;
  RUN bash -c 'cat /proc/$$/limits'
  # Placeholder, not used in this example
  CMD bash
  </code></pre>
  <p>If I run:</p>
  <pre><code>podman build -t project .
  </code></pre>
  <p>This prints (among other things):</p>
  <pre><code>Max open files            1024                 1024                 files     
  </code></pre>
  <p>Gee, that's low.</p>
  <p>If I become root in my shell and use <code>ulimit -n 131072</code>, then <code>cat /proc/self/limits</code> shows my increased limit in the shell. But if I then bump &quot;Clear cache 1&quot; to &quot;Clear cache 2&quot; in the Dockerfile (<strong>this is important</strong>) and run the build command, still in that root shell with the increased ulimit, I still get:</p>
  <pre><code>Max open files            1024                 1024                 files     
  </code></pre>
  <p>So that's what I see in <code>podman build</code>. However if I then open a bash shell in a container using the new image using <code>podman run</code>, I get this result:</p>
  <pre><code>root@ubuntu:/home/ubuntu/opt/cloud/build# podman run -it project bash
  root@17961323a1c9:/app# cat /proc/$$/limits
  Max open files            1048576              1048576              files     
  </code></pre>
  <p>The command has completely different results at build time and at &quot;run&quot; time.</p>
  <p>I did try to modify <code>ulimit</code> inside a RUN statement, but no dice:</p>
  <pre><code>bash: line 1: ulimit: open files: cannot modify limit: Operation not permitted
  Error: error building at STEP &quot;RUN bash -c 'ulimit -n 131072 &amp;&amp; cat /proc/$$/lim
  </code></pre>
  <p>Anyway it would be much better to increase this for the build command in general, or at least using an option to it, rather than for every RUN that might need it.</p>
  <p>Practically speaking this appears to be behind a build failure I have with a larger Dockerfile, but I've boiled it down to this straightforward test case.</p>
  <p>I have also tried using <code>docker</code> (real Docker Engine). The problem does not happen with Docker Engine, I get 1048576 files there during build.</p>
  <p>How can I increase the file descriptor limit at build time?</p>
  <p>Thank you!</p>
  <p><strong>Update:</strong> I'm told there is a <code>--ulimit</code> option to podman, and indeed there is. But podman 3.4.4, which is standard on Ubuntu 22.04, does not support the simple <code>--ulimit=host</code> version. I am trying to figure out what a valid option value looks like. I have tried:</p>
  <pre><code>--ulimit=n=131072:1048576
  --ulimit=NOFILES=131072:1048576
  </code></pre>
  <p>Both throw errors of the form:</p>
  <pre><code>requires name=SOFT:HARD, failed to be parsed: invalid ulimit type: n
  </code></pre>
  
Tags: <containers><podman>
Title: Processes in "podman build" have lower file descriptor limit than processes in "podman run", how can I increase this?
UserDisplayName: Tom Boutell
ThreadText: # Processes in "podman build" have lower file descriptor limit than processes in "podman run", how can I increase this?
  
  (Asked by: username_0 on 2023-08-17)
  
  I'm running podman 3.4.4 on Ubuntu 22.04 LTS server.
  
  I have been having `podman build` issues that are not reproducible if I do those steps after the container build using `podman run`.
  
  Eventually I traced it to this: the limits given to processes in `podman build` are completely different. Here's a sample Dockerfile:
  
  ```
  FROM node:14-bullseye
  WORKDIR /app
  RUN echo "clear cache 1"
  RUN bash -c 'cat /proc/$$/limits'
  # Placeholder, not used in this example
  CMD bash
  
  ```
  
  If I run:
  
  ```
  podman build -t project .
  
  ```
  
  This prints (among other things):
  
  ```
  Max open files            1024                 1024                 files     
  
  ```
  
  Gee, that's low.
  
  If I become root in my shell and use `ulimit -n 131072`, then `cat /proc/self/limits` shows my increased limit in the shell. But if I then bump "Clear cache 1" to "Clear cache 2" in the Dockerfile (**this is important**) and run the build command, still in that root shell with the increased ulimit, I still get:
  
  ```
  Max open files            1024                 1024                 files     
  
  ```
  
  So that's what I see in `podman build`. However if I then open a bash shell in a container using the new image using `podman run`, I get this result:
  
  ```
  root@ubuntu:/home/ubuntu/opt/cloud/build# podman run -it project bash
  root@17961323a1c9:/app# cat /proc/$$/limits
  Max open files            1048576              1048576              files     
  
  ```
  
  The command has completely different results at build time and at "run" time.
  
  I did try to modify `ulimit` inside a RUN statement, but no dice:
  
  ```
  bash: line 1: ulimit: open files: cannot modify limit: Operation not permitted
  Error: error building at STEP "RUN bash -c 'ulimit -n 131072 && cat /proc/$$/lim
  
  ```
  
  Anyway it would be much better to increase this for the build command in general, or at least using an option to it, rather than for every RUN that might need it.
  
  Practically speaking this appears to be behind a build failure I have with a larger Dockerfile, but I've boiled it down to this straightforward test case.
  
  I have also tried using `docker` (real Docker Engine). The problem does not happen with Docker Engine, I get 1048576 files there during build.
  
  How can I increase the file descriptor limit at build time?
  
  Thank you!
  
  **Update:** I'm told there is a `--ulimit` option to podman, and indeed there is. But podman 3.4.4, which is standard on Ubuntu 22.04, does not support the simple `--ulimit=host` version. I am trying to figure out what a valid option value looks like. I have tried:
  
  ```
  --ulimit=n=131072:1048576
  --ulimit=NOFILES=131072:1048576
  
  ```
  
  Both throw errors of the form:
  
  ```
  requires name=SOFT:HARD, failed to be parsed: invalid ulimit type: n
  
  ```
  
  **Tags:** containers, podman
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2023-08-17. Score: 3
  
  The following command works, cobbled together from friendly advice and additional googling based on that input:
  
  ```
  podman build --ulimit=nofile=131072:1048576 [other arguments here]
  
  ```
  
  The latest releases of `podman` accept `--ulimit=host`, which is convenient if you want the same policy, but 3.4.4 does not, and in any case `--ulimit=host` works only for `podman create` and `podman run`. For `podman build` specifying limit names is a requirement.
  
  For the file descriptor limit the proper name is `nofiles`. The
  [podman documentation for version 4.4](https://docs.podman.io/en/v4.4/markdown/podman-build.1.html#ulimit-type-soft-limit-hard-limit) describes additional valid limit names.
  
  
  ---
  
  ### Answer by username_1 on 2024-09-12. Score: 2
  
  To permanently raise the default ulimit, it's now possible to edit `/etc/containers/containers.conf` (or the same file at various other locations; see [`man containers.conf`](https://manned.org/man/containers.conf)):
  
  Something like this:
  
  ```
  [containers]
  default_ulimits = [
    "nofile=16384:524288",
  ]
  
  ```
  
  
  ---
  
  