如何使用dockerfile添加用户? [英] How to add user with dockerfile?
本文介绍了如何使用dockerfile添加用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Dockerfile添加用户-以下操作不起作用。
How can I add a user with Dockerfile - the following does not work.
USER vault
WORKDIR /usr/local/bin/vault
我的完整Dockerfile:
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
推荐答案
使用 useradd
而不是其交互式 adduser
来添加用户。
Use useradd
instead of its interactive adduser
to add user.
RUN useradd -ms /bin/bash vault
以下命令将不会创建用户。 / p>
Below command will not create user .
USER vault
WORKDIR /usr/local/bin/vault
它将使用 Vault
用户
请参考 Dockerfile用户文档
USER指令设置运行
映像以及Dockerfile中
之后的任何RUN,CMD和ENTRYPOINT指令时使用的用户名或UID。
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.
注意:确保 bash
是
如果默认外壳为 / bin / sh
,则可以执行以下操作:
If default shell is /bin/sh
you can do like:
RUN ln -sf /bin/bash /bin/sh
RUN useradd -ms /bin/bash vault
这篇关于如何使用dockerfile添加用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文