Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add user with dockerfile?

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

USER vault WORKDIR /usr/local/bin/vault 

My full Dockerfile:

FROM alpine:3.4 RUN apk update && apk add curl unzip RUN useradd -ms /bin/bash vault  USER vault WORKDIR /usr/local/bin/vault ADD /vault.hcl /etc/vault/vault.hcl  RUN curl -SL https://releases.hashicorp.com/vault/0.5.0/vault_0.5.0_linux_amd64.zip > vault.zip RUN unzip vault.zip -d /usr/local/bin && rm vault.zip 
like image 327
Atlantic0 Avatar asked Oct 04 '16 14:10

Atlantic0


People also ask

How do I add an admin user to Dockerfile?

Using Dockerfile Docker allows you to add the User using the −u flag along with the useradd command and then using the USER instruction, you can decide which user you want to be logged in as when you start the Docker Container.

What is user command in Dockerfile?

The default user in a Dockerfile is the user of the parent image. For example, if your image is derived from an image that uses a non-root user example: swuser , then RUN commands in your Dockerfile will run as swuser .


1 Answers

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 
like image 53
pl_rock Avatar answered Oct 07 '22 02:10

pl_rock