docker tutorials

docker: Error response from daemon: linux spec usepassw_unable to find user admin, no matching entries in passwd file.

This sneppets shows you how to resolveĀ docker: Error response from daemon: linux spec usepassw_unable to find user admin, no matching entries in passwd file.

When you are trying to run the following docker run command to list user and group information, it might result the following error.

$ docker run --rm -it sneppets/sshd-example id
docker: Error response from daemon: linux spec user: unable to find user admin: no matching entries in passwd file.

Solution

To resolve the above error, you need include the following command in your Dockerfile, which basically creates user admin and a home directory with bash as default shell.

RUN useradd -ms /bin/bash admin

Then add the following command to your Dockerfile.

USER admin

Therefore every command that is executed later including interactive sessions will use user admin as default user.

Dockerfile Example

The Dockerfile example below uses above instructions which installs openssh-server and enable ssh login for non-root user “admin“.

FROM ubuntu

MAINTAINER Admin <[email protected]>

RUN apt-get update && apt-get install -y openssh-server

RUN mkdir -p /var/run/sshd

RUN useradd -ms /bin/bash admin

ADD sshd_config /etc/ssh/sshd_config

CMD /usr/sbin/sshd -D

USER admin

WORKDIR /tmp

ENV hello "Hello World"

Then try to build using above Dockerfile and run docker container, user admin will be added to docker container successfully.

$ docker build -t sneppets/sshd-example .

Sending build context to Docker daemon  6.144kB
Step 1/10 : FROM ubuntu
 ---> 4e5021d210f6
Step 2/10 : MAINTAINER Admin<[email protected]>
 ---> Using cache
 ---> f8248d45bbbb
Step 3/10 : RUN apt-get update && apt-get install -y openssh-server
 ---> Using cache
 ---> 68b9e843c428
Step 4/10 : RUN mkdir -p /var/run/sshd
 ---> Using cache
 ---> ec1cad7fa3c5
Step 5/10 : RUN useradd -ms /bin/bash admin
 ---> Running in 1e2242a0f45b
Removing intermediate container 1e2242a0f45b
 ---> d679ac2040ee
Step 6/10 : ADD sshd_config /etc/ssh/sshd_config
 ---> b2f4a3b7dbe5
Step 7/10 : CMD /usr/sbin/sshd -D
 ---> Running in 1525580dc6a1
Removing intermediate container 1525580dc6a1
 ---> f5a3dadc06dd
Step 8/10 : USER admin
 ---> Running in fba4f45ea636
Removing intermediate container fba4f45ea636
 ---> 2ed419f892b3
Step 9/10 : WORKDIR /tmp
 ---> Running in f5c2b540b6e0
Removing intermediate container f5c2b540b6e0
 ---> 17fec4ad1ead
Step 10/10 : ENV hello "Hello World"
 ---> Running in 83f47615d138
Removing intermediate container 83f47615d138
 ---> daaf0c14f2a2
Successfully built daaf0c14f2a2
Successfully tagged sneppets/sshd-example:latest

Let’s try now to list users and groups information using the following command and it works.

$ docker run --rm -it sneppets/sshd-example id                                                               
uid=1000(admin) gid=1000(admin) groups=1000(admin)

Also See

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments