skip to Main Content

In Docker references, I didn’t find any information about how long the string can be passed to Docker CMD.

  1. What are the limitations?
  2. What is the maximum number of characters I can pass to CMD?

2

Answers


  1. I have done a simple test and found the limit of dockerfile line is 65535 on my CentOS 7/x64 machine.

    #./build.sh
    Sending build context to Docker daemon    363kB
    Error response from daemon: failed to parse Dockerfile: dockerfile line greater than max allowed size of 65535
    
    Login or Signup to reply.
  2. @ZenithS You’re right for Windows (8192 Characters), but Linux is not that easy.

    To make it short: For Linux it’s hardcoded to 64 or 128 kiB. You could check with xargs --show-limits, which gives a pretty detailed overview:

    Your environment variables take up 5354 bytes
    POSIX upper limit on argument length (this system): 2089750 <-- ARG_MAX
    POSIX smallest allowable upper limit on argument length (all systems): 4096
    Maximum length of command we could actually use: 2084396 <-- ARG_MAX - ENV
    Size of command buffer we are actually using: 131072 <-- Hardcoded limit which applies actually (see below)
    Maximum parallelism (--max-procs must be no greater): 2147483647
    

    The hardcoded limit goes to MAX_ARG_STRLEN which is set to PAGE_SIZE * 32
    https://github.com/torvalds/linux/blob/v5.16-rc7/include/uapi/linux/binfmts.h#L15

    With getconf PAGE_SIZE you can check (mostly 2048 or 4096 on modern platforms) so results to 64 or 128 kiB.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search