Create SSH Docker – CentOS latest
Quote from moshe on 24/10/2020, 6:59 amProblem
User wants to create an SSH docker for tests
Solution
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
EXPOSE 22
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
Test
ssh test@localhost -p 2222
Notes
- 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
Problem
User wants to create an SSH docker for tests
Solution
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
EXPOSE 22
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
Test
ssh test@localhost -p 2222
Notes
- 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:Quote from moshe on 02/12/2020, 12:02 pmif 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
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
Quote from moshe on 02/12/2020, 12:03 pmGet the IP address of the container, check connectivity and ssh
sudo docker inspect -f “{{ .NetworkSettings.IPAddress }}” Container_Name
ping –c 3 172.1.0.20
ssh root@172.1.0.20
Get the IP address of the container, check connectivity and ssh
sudo docker inspect -f “{{ .NetworkSettings.IPAddress }}” Container_Name
ping –c 3 172.1.0.20
ssh root@172.1.0.20