I have tried to put some commands on Dockerfile like :
But none of these commands is able to run ssh service after running the container.
Can anyone help here please ?
I have run SSH service in a Docker container successfully using the steps in this link.
Below is the Dockerfile that worked for me:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:THEPASSWORDYOUCREATED' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
You could also try the following Docker images on Docker Hub that enable SSH server inside a container: