Non-root user in Docker

2019-05-30 13:49发布

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?

1条回答
淡お忘
2楼-- · 2019-05-30 14:23

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

查看更多
登录 后发表回答