10

I seem to be missing some very basic utilities, namely the commands sudo and which seem to be missing. How can I install these, or even better is there an ami linux image which has all of these kind of things pre-installed.

Dockerfile:

FROM amazonlinux:2.0.20190823.1-with-sources
RUN echo $(which sudo)

Error:

/bin/sh: which: command not found

Or if I just try to use something like sudo yum

/bin/sh: sudo: command not found

Since it seems relevant, I also don't seem to have root permissions as trying to use the adduser command gives me a non zero response code of 2.

Shardj
  • 1,800
  • 2
  • 17
  • 43
  • 1
    `RUN yum update && yum install -y sudo`, sudo is not installed in that image by default. you are already root in that images so you do not need sudo yum – LinPy Sep 13 '19 at 09:23
  • Thanks, that's pretty crazy to me. Didn't realise you just used yum to install these regular commands. I feel a bit silly now. Pop that into an answer and I'll mark it as correct @LinPy – Shardj Sep 13 '19 at 09:27
  • 1
    You pretty much never need `sudo` in Docker. A container usually runs some single process as a foreground job without user intervention, so you don't usually need an interactive shell in a container, and if you do, you can always `docker exec -u 0` to be root. – David Maze Sep 13 '19 at 10:38
  • I need sudo for sudo -u, not for root permissions. Also in my case I use a docker container as a cli quite often since it has everything I need for the command line installed. Plenty runs in the background and it's often interactive. I also need sudo because prod uses sudo in some scripts, those same scripts need to work on my local. – Shardj Sep 13 '19 at 11:15

1 Answers1

10

RUN yum update && yum install -y sudo, sudo is not installed in that image by default. you are already root in that images so you do not need sudo yum.

the idea from not installing too many packages by default ,is to let the image as small as possible and let the user install just what he needs

LinPy
  • 16,987
  • 4
  • 43
  • 57