如何使用 dockerfile 添加用户? [英] How to add user with dockerfile?

查看:141
本文介绍了如何使用 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

以下命令不会创建用户.

Below command will not create user .

USER vault
WORKDIR /usr/local/bin/vault

它将使用 vault 用户

请参考 Dockerfile 用户文档

USER 指令设置运行时使用的用户名或 UID图像以及其后的任何 RUN、CMD 和 ENTRYPOINT 指令在 Dockerfile 中.

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 是默认 shell.

NOTE : Ensures that bash is the default shell.

如果默认 shell 是 /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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆