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?
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.
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.
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 .
by default docker container runs as root user
remove the sudo from Dockerfile and run again.
Your commands in the Dockerfile already run as root
during docker build
. For this reason you do not need to use sudo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With