Docker container with SSH does not run with --user flag

Viewed 112

I have a Dockerfile which builds with open_ssh. I want to run the container with a non-root user to grant files/folders with all the permissions automatically by default for that specific user.

If I run the image as follows:

docker run --user $(id -u):$(id -g) <name>:<tag>

the container doesn't start. I checked the logs and it says sshd: no hostkeys available -- exiting.

However, if I remove the --user flag it works as expected.

I am guessing it is because in the Dockerfile I am only giving access to root user

RUN echo 'root:root' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

Is there any option to be able to run the container with any user apart from root?

0 Answers
Related