Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/bin/sh: 1: sudo: not found when running dockerfile

Tags:

This is the content of my Dockerfile.

FROM ubuntu  RUN sudo apt-get update  RUN sudo apt-get install -y wget  CMD wget -O- -q http://ifconfig.me/ip 

When I run the Dockerfile to build a docker image, I get the below error:

/bin/sh: 1: sudo: not found

Can you please help me in solving the above error?

like image 222
mspms Avatar asked May 22 '19 05:05

mspms


People also ask

How do I fix sudo command not found?

Step 1: Install the 'sudo' command To achieve this, log in or switch to root user and use the APT package manager to update the system package list. Then install sudo as shown. When prompted to continue. hit 'Y' to proceed.

How do I run a docker container as a root user?

Docker containers are designed to be accessed as root users to execute commands that non-root users can't execute. We can run a command in a running container using the docker exec. We'll use the -i and -t option of the docker exec command to get the interactive shell with TTY terminal access.

How do I run a command in Dockerfile?

CMD is the command the container executes by default when you launch the built image. A Dockerfile will only use the final CMD defined. The CMD can be overridden when starting a container with docker run $image $other_command .


2 Answers

by default docker container runs as root user
remove the sudo from Dockerfile and run again.

enter image description here

like image 87
Abhishek D K Avatar answered Sep 17 '22 11:09

Abhishek D K


Your commands in the Dockerfile already run as root during docker build. For this reason you do not need to use sudo

like image 33
Mihai Avatar answered Sep 16 '22 11:09

Mihai