docker build with --build-arg with multiple arguments

后端 未结 4 1548
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 01:27

According to the documentation, it\'s possible to define multiple args for the flag --build-arg, but I can\'t find out how. I tried the following:

d         


        
相关标签:
4条回答
  • 2021-01-30 01:43

    Use --build-arg with each argument.

    If you are passing two argument then add --build-arg with each argument like:

    docker build \
    -t essearch/ess-elasticsearch:1.7.6 \
    --build-arg number_of_shards=5 \
    --build-arg number_of_replicas=2 \
    --no-cache .
    
    0 讨论(0)
  • 2021-01-30 01:58

    The above answer by pl_rock is correct, the only thing I would add is to expect the ARG inside the Dockerfile if not you won't have access to it. So if you are doing

    docker build -t essearch/ess-elasticsearch:1.7.6 --build-arg number_of_shards=5 --build-arg number_of_replicas=2 --no-cache .
    

    Then inside the Dockerfile you should add

    ARG number_of_replicas
    ARG number_of_shards
    

    I was running into this problem, so I hope I help someone (myself) in the future.

    0 讨论(0)
  • 2021-01-30 01:59

    If you want to use environment variable during build. Lets say setting username and password.

    username= Ubuntu
    password= swed24sw
    

    Dockerfile

    FROM ubuntu:16.04
    ARG SMB_PASS
    ARG SMB_USER
    # Creates a new User
    RUN useradd -ms /bin/bash $SMB_USER
    # Enters the password twice.
    RUN echo "$SMB_PASS\n$SMB_PASS" | smbpasswd -a $SMB_USER
    

    Terminal Command

    docker build --build-arg SMB_PASS=swed24sw --build-arg SMB_USER=Ubuntu . -t IMAGE_TAG

    0 讨论(0)
  • 2021-01-30 01:59

    It's a shame that we need multiple ARG too, it results in multiple layers and slows down the build because of that, and for anyone also wondering that, currently there is no way to set multiple ARGs.

    0 讨论(0)
提交回复
热议问题