Make centos docker image with openssh service

1. Install docker server
To install docker server under linux, you can use yum installation (for redhat and centos)
yum install -y docker

2. Start the docker service
systemctl start docker (start)
systemctl enable docker (set to boot)

3. View available mirror
docker images

4. Register a docker hub account
and download the image from the docker hub warehouse

5. Pull the basic centos image
docker pull docker.io/centos:7.3.1611
here is the 7.3.1611 version, that is, the docker tag specifies 7.3.1611, there is no openssh service in the image, it needs to be installed before can connect remotely

6. Start the centos image
docker run -d -it --name centos --privileged=true docker.io/centos:7.3.1611 /usr/sbin/init
The privileged mode is added here, otherwise the systemctl command in the container will be used There is an error reporting that the D-Bus service connection failed

7. Enter the docker image
docker exec -it centos /bin/bash
or docker exec -it {container id} /bin/bash
Here you can use the name of the docker container, or you can use the id of the docker container to enter the container

8. Install openssh service
yum -y install openssh-server
yum -y install openssh-clients
modify /etc/ssh/sshd_config configuration file
vi /etc/ssh/sshd_config
modify setting UsePAM no
comment #HostKey /etc/ssh/ssh_host_ecdsa_key
comment# HostKey /etc/ssh/ssh_host_ed25519_key

Set container root user password
passwd or echo "root:password"|chpasswd

Start the sshd service
systemctl start sshd.service
systemctl enable sshd.service

9. Exit the container
exit

10. Generate mirror
docker ps -a
docker commit perfiffer/centos-base:7.3.1611
docker images

11. Run the newly generated image
docker run -d -it -p 10022:22 --name centos perfiffer/centos-base:7.3.1611

12. Push the generated image to docker hub
docker push perfiffer/centos-base:7.3.1611

Guess you like

Origin blog.csdn.net/x1172031988/article/details/83109711