Docker creates containers and mirrors that support SSH services
-
Use CentOS as a container here, so first download CentOS images
Sudo docker pull CentOS
-
Download and run a CentOS container, Here I use CENTOS6 as my Test Container
Sudo docker run--name=centos-ssh-i-T centos:centos6/bin/bash
-
Install the Openssh-server service package
Yum install openssh-server
-
Edit sshd configuration file/etc/ssh/sshd_config, Set the Usepam parameter to "no"
-
Start the sshd service
/etc/init.d/sshd start
-
Add test user admin, password admin
Useradd Admin
Echo ' admin:admin ' | chpasswd
-
In order for the newly added user to run the sudo command, it is necessary to install the sudo package and add the admin to sudoers
Yum install sudo <--install sudo package
Visudo < ---Edit sudoers, add the following line to the file
Admin all= (All) all
-
Test, after the above work, use ifconfig to view the container's IP, or use the sudo docker Inspect "View, then you can access the newly created Docker container via SSH [email protected]<ip> on the host machine.
-
If you want to make the container that supports the SSH service as a Docker image, first exit the container, and then use the following command to create the
sudo docker commit <container id> <image name>
Docker creates containers and mirrors that support SSH services