How to add user with dockerfile?

后端 未结 2 841
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 01:05

How can I add a user with Dockerfile - the following does not work.

USER vault
WORKDIR /usr/local/bin/vault

My full Dockerfile:

<         


        
相关标签:
2条回答
  • 2020-12-24 01:34

    Use useradd instead of its interactive adduser to add user.

    RUN useradd -ms /bin/bash  vault
    

    Below command will not create user .

    USER vault
    WORKDIR /usr/local/bin/vault
    

    it will use vault user

    please Refer Dockerfile User Documentation

    The USER instruction sets the user name or UID to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.

    NOTE : Ensures that bash is the default shell.

    If default shell is /bin/sh you can do like:

    RUN ln -sf /bin/bash /bin/sh
    RUN useradd -ms /bin/bash  vault
    
    0 讨论(0)
  • 2020-12-24 01:36

    To add group and to associate a new user, use code below.

    FROM <base image>
    RUN groupadd -g 2000 go \
    && useradd -m -u 2001 -g go go
    USER go
    

    OR

    RUN addgroup -g 1001 -S appuser && adduser -u 1001 -S appuser  -G appuser 
    
    0 讨论(0)
提交回复
热议问题