[ root@shendu ~]# docker version
Client:
Version:1.13.1
API version:1.26
Package version: docker-1.13.1-102.git7f2769b.el7.centos.x86_64
Go version: go1.10.3
Git commit: 7f2769b/1.13.1
Built: Mon Aug 515:09:422019
OS/Arch: linux/amd64
Server:
Version:1.13.1
API version:1.26(minimum version 1.12)
Package version: docker-1.13.1-102.git7f2769b.el7.centos.x86_64
Go version: go1.10.3
Git commit: 7f2769b/1.13.1
Built: Mon Aug 515:09:422019
OS/Arch: linux/amd64
Experimental:false[root@shendu ~]#
[ root@shendu ~]# uname -a
Linux shendu 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 1222:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[ root@shendu ~]#
[ root@shendu ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810(Core)[root@shendu ~]#
Description:
In view of the domestic network problems, it is very slow to pull the Docker image, and it needs to be set to a domestic image before installation, which can be accelerated.
I am using NetEase’s mirror address: http://hub-mirror.c.163.com
NetEase Cloud Mirror official address https://c.163yun.com/hub#/library/repository/info?repoId=1055
[ root@shendu ~]#
[ root@shendu ~]# cat /etc/docker/daemon.json
{" registry-mirrors":["http://hub-mirror.c.163.com"]}[root@shendu ~]#
sudo systemctl daemon-reload
sudo systemctl restart docker
Create a Dockerfile file: (I created it directly in the root user directory)
document content:
FROM hub.c.163.com/netease_comb/centos:7
MAINTAINER netease
# Update yum source
RUN yum makecache fast && yum -y update glibc
# Install common software
RUN yum install -y openssh-server vim tar wget curl rsync bzip2 iptables tcpdump less telnet net-tools lsof
# Initialize ssh login
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
RUN ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
RUN echo "RSAAuthentication yes">>/etc/ssh/sshd_config
RUN echo "PubkeyAuthentication yes">>/etc/ssh/sshd_config
RUN yum clean all
# Start the sshd service and expose port 22
RUN mkdir /var/run/sshd
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
Run under the folder of Dockerfile
: docker build -t centos7-my .
centos7-my
is the name of the generated image
If successful, execute docker images
and you will see the following result
docker run -itd --name os1 -p 10000:22 87bd98509c5e /bin/bash
- - name os1
: the name of the container that started the container87 bd98509c5e
: mirror id- p 10000:22
: Port mapping, map container 22
port to Host10000
port for subsequent SSH remote login1、 Enter the os1 container:
Command: docker exec -it os1 bash
[ root@shendu ~]#
[ root@shendu ~]# docker exec -it os1 bash
[ root@d6898c947c4b /]#
[ root@d6898c947c4b /]#
2、 Start ssh:
[ root@d6898c947c4b /]# /usr/sbin/sshd -D
[ root@d6898c947c4b /]# /usr/sbin/sshd -D &
3、 Check if it has started successfully
Use the command: netstat -ntpl |grep 22
or lsof -i:22
[ root@d6898c947c4b /]#
[ root@d6898c947c4b /]# netstat -ntpl |grep 22
tcp 000.0.0.0:220.0.0.0:* LISTEN 44/sshd
tcp6 00:::22:::* LISTEN 44/sshd
[ root@d6898c947c4b /]#
[ root@d6898c947c4b /]#
[ root@d6898c947c4b /]# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 44 root 3u IPv4 32153435 0t0 TCP *:ssh(LISTEN)
sshd 44 root 4u IPv6 32153437 0t0 TCP *:ssh(LISTEN)[root@d6898c947c4b /]#
[ root@d6898c947c4b /]#
[ root@d6898c947c4b /]#
If the above results appear, it is considered a success.
[ root@d6898c947c4b /]#
[ root@d6898c947c4b /]# passwd root
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype newpassword:
passwd: all authentication tokens updated successfully.[root@d6898c947c4b /]#
Recommended Posts