Score:0

Execute a bash script containing the sudo command in rootless docker

gb flag

I am working in a rootless docker environment and I want to execute a shell script that contains some commands with sudo, but the command sudo is not recognized in my terminal (probably because it is a rootless docker). I get the following error:

sudo: command not found

How can I execute my shell script without changing it? (I do not want to manually delete the sudo commands, in a rootless docker I just need to ignore the sudo and execute the rest of the line).

I tried to make an alias for sudo in the .bashrc as follows:

alias sudo='',

but it is not a correct solution, because for some lines we have:

sudo -u username ....

Artur Meinild avatar
vn flag
This is probably one of the reasons including `sudo` statements in a shell script is a very bad idea..
Score:1
gb flag

That may sound crazy, but I fixed the issue by just installing sudo!

apt install sudo

After that, the rootless docker is similar to a normal one.

Score:0
cr flag

Running sudo statements on Docker is a bad idea. However, you can always try to execute the script outside docker with docker exec -ti --user root container /path/to/script or create a Dockerfile with you script.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.