5

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?

Sienna
  • 1,570
  • 3
  • 24
  • 48
  • 5
    Possible duplicate of [Add User to Docker Container](http://stackoverflow.com/questions/27701930/add-user-to-docker-container) – Felix Glas Feb 15 '17 at 00:02

1 Answers1

18

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

Ricardo Branco
  • 5,740
  • 1
  • 21
  • 31