Bhagya Jayantha
Bhagya Jayantha

Reputation: 21

How ro run sudo su - in Dockerfile

I am trying to RUN sudo su - inside the Dockerfile and I get this error

/bin/sh: 1: sudo: not found

This is how my Dockerfile looks like:

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?

Upvotes: 2

Views: 3355

Answers (3)

Guido U. Draheim
Guido U. Draheim

Reputation: 3271

The dockerfile will run as a virtual "root" user by default, so there is no need to include any sudo command.

Since the example script contains no "-y" defaults it seems that you have simply typed the description for a manual installation into a script. This will never work. And well, in a container the application does also need to be on PID-1 which systemctl will not do.

After going through a basic tutorial on docker you will find out why.

Upvotes: 2

Fuji Komalan
Fuji Komalan

Reputation: 2047

$ 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

Upvotes: 0

Victor
Victor

Reputation: 3688

This command seems not to be doing anything except for creating an extra layer without any useful effect.

Upvotes: 1

Related Questions