User authentication failure with user add on ubuntu14.04 container

I am running docker on mac using toolbox. Downloaded the ubuntu and created a user…
Am I doing something wrong here?

—Error------
root@69c9681c63db:/var/log# useradd testusr -d /home/testusr -m -s /bin/bash -p DM12e5 -g docker
root@69c9681c63db:/var/log# su - testusr
testusr@69c9681c63db:~$ su - testusr
Password:

su: Authentication failure

testusr@69c9681c63db:~$

----version—
Client:
Version: 1.11.0
API version: 1.23
Go version: go1.5.4
Git commit: 4dc5990
Built: Wed Apr 13 18:13:28 2016
OS/Arch: darwin/amd64

Server:
Version: 1.11.0
API version: 1.23
Go version: go1.5.4
Git commit: 4dc5990
Built: Wed Apr 13 19:36:04 2016
OS/Arch: linux/amd64

thanks for input…

-Manoj

Hi Manoj,

The mistake you are doing here is the way you are passing password to useradd command. -p option of useradd command expects the password to be encrypted.

  -p, --password PASSWORD       encrypted password of the new account

You can use openssl to create crypted password and use it in your command.

openssl passwd -crypt

Regards

Thanks Ranjan for your response…

Sorry I didn’t quite get that…Did you mean :-
PASS=$(openssl passwd -crypt testpwd)
useradd testuser -p $PASS?

wouldn’t that be a string again? or may be I misunderstood your suggestion…

thanks for your time,

Hi,

Ofcourse it will be again a string. That doesnt matter. Only thing is -p should be password with an encrypted version of your password, which is what you are getting using the openssl command.

Regards

I wouldn’t bother trying to set a password. Either put a USER directive in your Dockerfile, or use the docker run -u or docker exec -u options to run a process or get a shell as that user.

Yes Ranjan, got your point, looks more on linux side than containers. thanks…
David, yes…it makes more sense…thanks for suggestions.