当我使用Alpine作为基本图像时,如何添加用户? [英] How do I add a user when I'm using Alpine as a base image?

查看:102
本文介绍了当我使用Alpine作为基本图像时,如何添加用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 alpine (或基于Alpine的映像)作为我的Dockerfile中的基础映像.创建用户需要添加哪些说明?

I'm using alpine (or an image that is based on Alpine) as the base image in my Dockerfile. Which instructions do I need to add to create a user?

最终,我将使用该用户来运行将放置到容器中的应用程序,以便root用户不会这样做.

Eventually I'll use this user to run the application I'll place into the container so that the root user does not.

推荐答案

Alpine使用命令 adduser addgroup 创建用户和组(而不是 useradd usergroup ).

Alpine uses the command adduser and addgroup for creating users and groups (rather than useradd and usergroup).

FROM alpine:latest

# Create a group and user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup

# Tell docker that all future commands should run as the appuser user
USER appuser

adduser 的标志为:


Usage: adduser [OPTIONS] USER [GROUP]

Create new user, or add USER to GROUP

        -h DIR          Home directory
        -g GECOS        GECOS field
        -s SHELL        Login shell
        -G GRP          Group
        -S              Create a system user
        -D              Don't assign a password
        -H              Don't create home directory
        -u UID          User id
        -k SKEL         Skeleton directory (/etc/skel)

添加新的用户官方文档

这篇关于当我使用Alpine作为基本图像时,如何添加用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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