In the beginning of Docker, the ubuntu system image has been downloaded, and a simple system command was successfully executed after starting the container
At this time, the container is closed. Next, we will establish a communication bridge with the container-configure SSH service
Here use centos mirroring for configuration
step
(1) Download the centos base image
(2) Write an integrated configuration file to support ssh on top of the basic image
(3) Run the configuration file and create a new image that supports ssh
(4) Run the container and start the ssh service at the same time
(5) Test, connect to the container with the ssh command
operating
(1) Download the centos base image
Execute download mirror command
# docker pull centos
(2) Write configuration files
Create a new test directory and create a new configuration file under it
# vi Dockerfile
content:
FROM centos
MAINTAINER dys "[email protected]"
RUN yum install -y openssh openssh-server openssh-clients
RUN mkdir -p /var/run/sshd
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN /bin/echo 'root:aaaaaa'|chpasswd
RUN useradd dys
RUN /bin/echo 'dys:aaaaaa'|chpasswd
RUN /bin/sed -i 's/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g'/etc/pam.d/sshd
RUN /bin/echo -e "LANG=\"en_US.UTF-8\"">/etc/default/local
EXPOSE 22
CMD /usr/sbin/sshd -D
(3) Run the configuration file and create a mirror
Execute in the directory where the Dockerfile file is located:
docker build -rm -t dys/centos:ssh .
When the execution is complete, use the docker images command to see the mirror dys/centos just created
(4) Run the container
Execute the command to start the container
docker run -d -p 22 dys/centos:ssh
Use the docker ps command to check whether the startup is successful
If you see the name of the image you just created, it means that the container has run successfully
0.0.0.0:1035- >22 /tcp indicates that port 22 corresponds to port 1035, we can use the ssh client to connect
(5) Connection test
Use ssh command to connect to the container
User: dys is added to the above configuration file, and password: aaaaaa
ssh [email protected] -p 1035
Enter the password aaaaaa
Enter the container's command line
The most important thing in this process is the preparation of the Dockerfile configuration file, which will be described in detail later
Recommended Posts