Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use sudo commands within Docker, "bash: sudo: command not found" is displayed

I have installed TensorFlow using the following command

docker run -it b.gcr.io/tensorflow/tensorflow:latest-devel

and I need to set up TensorFlow Serving on a windows machine. I followed the instructions and while running the below-mentioned sudo command while installing TensorFlow Serving dependencies:

sudo apt-get update && sudo apt-get install -y \
     build-essential \
     curl \
     git \
     libfreetype6-dev \
     libpng12-dev \
     libzmq3-dev \
     pkg-config \
     python-dev \
     python-numpy \
     python-pip \
     software-properties-common \
     swig \
     zip \
     zlib1g-dev

The following error is displayed:

bash: sudo: command not found
like image 740
Vasanti Avatar asked Oct 11 '16 19:10

Vasanti


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 fix sudo command not found Mac?

Before attempting to fix this error double check the syntax to ensure the command you're trying to run is correct. If you haven't done so yet you'll need to enable the root user, this may be all that's needed to fix the error.

How to solve -Bash sudo command not found error?

-bash: sudo: command not found Error and Solution Step #1: Become a root user. When prompted you need to type the root user’s password. Step #2: Install sudo tool under Linux. Reading package lists... Done Building dependency tree Reading state information. Step #3: Add admin user to /etc/sudoers. ...

What does it mean when Sudo is not installed?

This error means the sudo command is not installed. The sudo command allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file. When prompted you need to type the root user’s password.

How to use sudo with Docker image?

docker comes along with root it doesnt require sudo. now you can use sudo along with your command in docker... Show activity on this post. Docker images typically do not have sudo, you are already running as root by default. Try If you wish to not run as root, see the Docker documentation on the User command.

What is sudo command in Linux?

Most of the Linux distributions provides the sudo command in order to run different tools and commands with root privileges. A regular user can run tools and commands with root privileges by using the sudo but the user should be configured to access sudo command.


3 Answers

docker comes along with root it doesnt require sudo.

BTW if you want sudo in docker if you want to install sudo,

try this,

apt-get update && \
      apt-get -y install sudo

now you can use sudo along with your command in docker...

like image 87
Mohideen bin Mohammed Avatar answered Oct 23 '22 14:10

Mohideen bin Mohammed


Docker images typically do not have sudo, you are already running as root by default. Try

apt-get update && apt-get install -y build-essential curl git libfreetype6-dev libpng12-dev libzmq3-dev pkg-config python-dev python-numpy python-pip software-properties-common swig zip zlib1g-d

If you wish to not run as root, see the Docker documentation on the User command.

like image 25
Sam Myers Avatar answered Oct 23 '22 12:10

Sam Myers


We don't want to weaken the security of the container by installing sudo in it. But we also don't want to change existing scripts that work on normal machines just so that they work in docker, which doesn't need the sudo.

Instead, we can define a dummy bash script to replace sudo, which just executes the arguments without elevating permissions, and is only defined inside the docker image.

Add this to your Dockerfile:

# Make sudo dummy replacement, so we don't weaken docker security
RUN echo "#!/bin/bash\n\$@" > /usr/bin/sudo
RUN chmod +x /usr/bin/sudo
like image 3
TamaMcGlinn Avatar answered Oct 23 '22 12:10

TamaMcGlinn