Create a user in a Dockerfile : Option d is ambiguous

Viewed 3337

I'm writing a Dockerfile where I want to create a user and use it instead of root user because that's a recommended practice.

I do the following:

FROM python:3
WORKDIR /app
RUN adduser -D myuser
USER myuser
...

docker-compose up rewards me with the following error message:

...    
Option d is ambiguous (debug, disabled-login, disabled-password)
ERROR: Service 'webapp' failed to build: The command '/bin/sh -c adduser -D myuser' returned a non-zero code: 1

That -d flag if often used (e.g. here) to create a user in a dockerfile but I can't figure out what it is supposed to be, disabled-password ?

1 Answers
  • Your docker-compose up is failing in the build step. When docker is trying to build the image, it encounters an error at line RUN adduser -D myuser
  • https://linux.die.net/man/8/useradd . You can read the manual what the flags mean.
  • Remove -D flag, i.e, change the command to RUN adduser myuser, new user will be added and build will be able to proceed to next step.
  • If you want to change defaults of adduser, you can read use the flags in the docs shared above.
Related