Docker 拉取centOs映象及遠端訪問
阿新 • • 發佈:2021-07-01
一、docker拉取centOs映象
使用docker命令進行拉取:
docker pull centos : 此種方式是拉取最新版的centOs映象,
docker pull centos:[版本] :這種方式可以拉取不同版本的centOs映象
二、執行centOs容器
使用命令:docker run -it -d --name centos-latest -p 5000:22 --privileged=true centos /sbin/init
=======================================================================================
centOs映象只是最基本的骨架,好多命令不支援,所以先安裝一些常用的命令:
1. 安裝網路環境
yum -y install net-tools
2. 安裝openssh-server
yyum -y install openssh-server
3. 安裝vim
yum install vim
4. 安裝passwd
yum install passwd
4.1. 修改root密碼
[root@7a1b1888cc86 /]# passwd
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@7a1b1888cc86 /]#
三、啟動容器sshd服務
[root@7a1b1888cc86 /]# /usr/sbin/sshd
如果出現下面的情況:
[root@7a1b1888cc86 /]# /usr/sbin/sshd Unable to load host key: /etc/ssh/ssh_host_rsa_key Unable to load host key: /etc/ssh/ssh_host_ecdsa_key Unable to load host key: /etc/ssh/ssh_host_ed25519_key sshd: no hostkeys available -- exiting.
執行1:
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ""
[root@7a1b1888cc86 /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" Generating public/private rsa key pair. Your identification has been saved in /etc/ssh/ssh_host_rsa_key. Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub. The key fingerprint is: SHA256:ythgDxqFyYmXYuY1X/Lin8txH5jmwoDtazqePCCdVXs root@7a1b1888cc86 The key's randomart image is: +---[RSA 3072]----+ | | | o = . | |ooBo.o o | |+o..+ = E | | o.o*o oS | |..o=.X.. o | |. o o.B. = . | | .o.ooo* . . | | .==..=o. . | +----[SHA256]-----+
執行2:
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ""
[root@7a1b1888cc86 /]# ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" Generating public/private ecdsa key pair. Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key. Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub. The key fingerprint is: SHA256:6y/gjIVmy6NzaD9i1qTESiJVKxW4aRHvOc0adOG8A+Y root@7a1b1888cc86 The key's randomart image is: +---[ECDSA 256]---+ | .o... | | o.oo . | | *=.+ | | *=.* . | | + .E.= S | |o.o =+o. . | |+o O.* .. | |. O O o.. | | +.*.o .o. | +----[SHA256]-----+
執行3:
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
[root@7a1b1888cc86 /]# ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" Generating public/private ed25519 key pair. Your identification has been saved in /etc/ssh/ssh_host_ed25519_key. Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub. The key fingerprint is: SHA256:MpXueojz012ZGl29vrQCr18E3H0oGs/fzmYV8ZVUf1Q root@7a1b1888cc86 The key's randomart image is: +--[ED25519 256]--+ | ..E| | . . .=+| | o . .o.oO| | o = .o.=| | o S ..o+ .o| | + ..=..o.| | . o.. +o ooo| | o o.o o oo++| | ooo .o..=+| +----[SHA256]-----+
最後看下是否成功:
[root@7a1b1888cc86 /]# netstat -antp | grep sshd [root@7a1b1888cc86 /]# /usr/sbin/sshd [root@7a1b1888cc86 /]# netstat -antp | grep sshd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 48/sshd tcp6 0 0 :::22 :::* LISTEN 48/sshd [root@7a1b1888cc86 /]#
OK,已經可以遠端訪問啦!