简体   繁体   English

如何在 Dockerfile 中运行 sudo su

[英]How ro run sudo su - in Dockerfile

I am trying to RUN sudo su - inside the Dockerfile and I get this error我正在尝试RUN sudo su -在 Dockerfile 中,但出现此错误

/bin/sh: 1: sudo: not found /bin/sh: 1: sudo: 未找到

This is how my Dockerfile looks like:这是我的Dockerfile样子:

FROM ubuntu:18.04
RUN sudo su - 
RUN apt update && install openjdk-8-jdk
RUN wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - && sudo sh -c  'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/kenkins.list'
RUN apt update && apt install jenkins

RUN curl -fsSL get.docker.com | /bin/bash
RUN usermod -aG docker jenkins && systemctl restart jenkins

This error comes when I try to build it.当我尝试构建它时会出现此错误。 docker build -t jenkins . Can someone help me?有人能帮我吗?

除了创建一个没有任何有用效果的额外图层之外,此命令似乎没有做任何事情。

The dockerfile will run as a virtual "root" user by default, so there is no need to include any sudo command.默认情况下,dockerfile 将以虚拟“root”用户身份运行,因此无需包含任何 sudo 命令。

Since the example script contains no "-y" defaults it seems that you have simply typed the description for a manual installation into a script.由于示例脚本不包含“-y”默认值,因此您似乎只是将手动安装的描述输入到脚本中。 This will never work.这永远不会奏效。 And well, in a container the application does also need to be on PID-1 which systemctl will not do.好吧,在容器中,应用程序也需要在 PID-1 上,而 systemctl 不会这样做。

After going through a basic tutorial on docker you will find out why.在完成有关 docker 的基本教程后,您将了解原因。

$ cat Dockerfile

FROM ubuntu:18.04
RUN apt-get update && apt-get install openjdk-8-jdk -y

If You want to change the use privilege use USER flag in Dockerfile如果要更改使用权限,请在 Dockerfile 中使用USER标志

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM