Ubuntu n00b here. I am tinkering with a Docker container that I created using the following simple Dockerfile:
FROM ubuntu
CMD ["tail","-f","/dev/null"]
Inside the container, as the root user, I try running visudo
and get the following response:
bash: visudo: command not found
I ran ls /etc
and it seems I don't have a sudoers file either.
Is there something special I should have put in my Dockerfile to make these exist?
I worked it out from another answer:
sudo
is not installed by default. To installsudo
:When you built the container, you are root so you can create users without sudo.
If you are deriving a container image that already has a
USER
directive, you can still become root again withUSER root
before using privileged commands. You can later issue anotherUSER
directive to become the execution user again. In other words:An image that sets a non privilege user:
Run with
docker run --rm plainuser
to check that it indeed runs with userappuser
.Let's derive it:
Run with
docker run --rm otheruser
.