When I execute docker run command or docker exec command, it doesnt ask for any password. Is there any way to ensure that when we enter docker exec or run command, it always asks for the password?
When I execute docker run command or docker exec command, it doesnt ask for any password. Is there any way to ensure that when we enter docker exec or run command, it always asks for the password?
There's no way to do this. Docker containers generally don't have "users"; to the extent that they do, they almost never have passwords set; and you don't "log in" to them, you just run a command.
For example, a typical command to get a debugging shell
docker run --rm -u root --entrypoint /bin/sh -it imagename
directly runs the interactive shell, as root, with no checks. Docker jumps straight into the sh process; there is nothing before it that would have the possibility of checking a password.
If you're trying to use this as a way to hide the image's contents, you can't. Anyone who can run any docker command at all can access any file in any container, and can pretty much trivially root the entire host system.
What is it that you want to achieve/avoid by introducing a password? Which Operating System are those container running on? Debian / Ubuntu / CentOS / Fedora / Windows ...?
You could look into sudo privileges.
Here you can specify that user X is allowed to use sudo with his user password to run any docker command. Depending on your OS you could specify this in the /etc/sudoer file or via visudo.