How to define a variable in a Dockerfile?

后端 未结 6 1178
情歌与酒
情歌与酒 2020-12-07 16:02

In my Dockerfile, I would like to define variables that I can use later in the Dockerfile.

I am aware of the

6条回答
  •  -上瘾入骨i
    2020-12-07 16:40

    Late to the party, but if you don't want to expose environment variables, I guess it's easier to do something like this:

    RUN echo 1 > /tmp/__var_1
    RUN echo `cat /tmp/__var_1`
    RUN rm -f /tmp/__var_1
    

    I ended up doing it because we host private npm packages in aws codeartifact:

    RUN aws codeartifact get-authorization-token --output text > /tmp/codeartifact.token
    RUN npm config set //company-123456.d.codeartifact.us-east-2.amazonaws.com/npm/internal/:_authToken=`cat /tmp/codeartifact.token`
    RUN rm -f /tmp/codeartifact.token
    

    And here ARG cannot work and i don't want to use ENV because i don't want to expose this token to anything else

提交回复
热议问题