Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-root user in Docker

I have a basic Dockerfile:

FROM ubuntu:xenial
USER test
ENTRYPOINT ["/bin/bash"]

For this Dockerfile, I want to be able to create a user without a password, and when the Docker container is run, I want that user to be used, instead of root. When I try to run the container, docker run -it test:1, I get this error:

docker: Error response from daemon: linux spec user: unable to find user test: no matching entries in passwd file.

How can I create a user in a Dockerfile and have that user be the default user when the container is run interactively?

like image 999
SiennaD. Avatar asked Dec 01 '22 12:12

SiennaD.


1 Answers

Add RUN useradd -s /bin/bash user before the USER directive.

like image 161
Ricardo Branco Avatar answered Dec 05 '22 06:12

Ricardo Branco