在Dockerfile中使用sudo(Alpine) [英] Use sudo inside Dockerfile (Alpine)

查看:2346
本文介绍了在Dockerfile中使用sudo(Alpine)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个Dockerfile ...

I have this Dockerfile ...

FROM keymetrics/pm2:latest-alpine

RUN apk update && \
    apk upgrade && \
    apk add \
       bash

COPY . ./

EXPOSE 1886 80 443

CMD pm2-docker start --auto-exit --env ${NODE_ENV} ecosystem.config.js

如何使用sudo执行CMD命令?

我需要这样做,因为仅sudo用户允许使用端口443.

I need to do this because the port 443 is allowed only for sudo user.

推荐答案

su-exec可以在高山中使用. 将其添加到软件包中,如果尚不可用,则将以下内容添加到您的Dockerfile中

The su-exec can be used in alpine. Do add it the package, if not already available, add the following to your Dockerfile

RUN apk add --no-cache su-exec

在您将要在docker中运行的脚本中,您可以使用以下内容来成为另一个用户:

Inside your scripts you'd run inside docker you can use the following to become another user:

exec su-exec <my-user> <my command>

或者,您可以在构建docker-file时添加更多familiair sudo程序包 将以下内容添加到来自高山的Dockerfile

Alternatively, you could add the more familiair sudo package while building your docker-file Add the following to your Dockerfile that's FROM alpine

RUN set -ex && apk --no-cache add sudo

之后,您可以使用sudo

After that you can use sudo

sudo -u <my-user> <my command>

这篇关于在Dockerfile中使用sudo(Alpine)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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