Forum Navigation
You need to log in to create posts and topics.

Create SSH Docker – CentOS latest


User wants to create an SSH docker for tests


Create a file called Dockerfile in the directory for the build (or download the docker file ) and copy this contents

FROM centos:latest
RUN yum -y install openssh-clients openssh-server && \
yum -y clean all && \
touch /run/utmp && \
chmod u+s /usr/bin/ping && \
RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test
RUN echo ‘test:test’ | chpasswd
#RUN echo “root:root” | chpasswd
RUN service ssh start
RUN mkdir -p /usr/local/tracston
RUN ssh-keygen -A
CMD [“/usr/sbin/sshd”,”-D”]

Build the Docker

sudo docker build -t SSHcontainer -f Dockerfile .

Run the Docker

sudo docker run -d -p 2222:22 SSHcontainer


ssh test@localhost -p 2222


  • the port exposd for the docker during docker run is 2222
  • Change the default user: test, password: test in the Docker file
  • if you want to install Centos7 change the first line in Docker file FROM centos:latest to FROM centos:7

IMPORTANT NOTE: Forum software changes special characters which are not useable to run as commands. please review and change accordingly

Uploaded files:

if you get error Exiting 127 add the following commands

RUN yum –y install openssh-server openssh-clients

RUN service sshd start

RUN service sshd enable

RUN service sshd status

Get the IP address of the container, check connectivity and ssh


sudo docker inspect -f “{{ .NetworkSettings.IPAddress }}” Container_Name

ping –c 3

ssh root@