本篇 blog 真心靠谱
1、备份原来的默认源
cp /etc/apt/sources.list{,.bak}
2、换阿里云的源(需要稍作修改)
直接使用阿里云的会报错
https://developer.aliyun.com/mirror/ubuntu
以上报错:是https证书问题,网上有人说安装证书,尝试不得行
apt-get install ca-certificate
很郁闷,转念想到,其实 so easy
于是修改 https 为 http
因为当前用不了vim/vi编辑器,所以使用cat写入文件
cat <<EOF> /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF
3、更新源
成功
apt-get update
啊就这,其实真的 so easy
4、安装测试
安装vim编辑器
apt install vim -y
安装vim编辑器,成功
安装 openssh-server
apt install openssh-server -y
最后,贴一下关键操作记录
[root@docker bin]# cat 01_run-u1804.sh
#!/bin/bash
docker run -dit \
--name u1804-d1 \
--privileged \
-p 10022:22 \
-h u1804-docker-1 \
ubuntu:18.04 \
/bin/bash
[root@docker bin]#
[root@docker bin]# sh 01_run-u1804.sh
ab45f34db2e23d126a9e294aedb2f878bea4a016e483cb4c61f26173f6dc9817
[root@docker bin]#
[root@docker bin]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab45f34db2e2 ubuntu:18.04 "/bin/bash" 4 seconds ago Up 3 seconds 0.0.0.0:10022->22/tcp u1804-d1
[root@docker bin]#
[root@docker bin]# docker exec -it ab4 bash
root@u1804-docker-1:/#
root@u1804-docker-1:/# cp /etc/apt/sources.list{,.bak}
root@u1804-docker-1:/#
root@u1804-docker-1:/# cat <<EOF> /etc/apt/sources.list
> deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
> EOF
root@u1804-docker-1:/#
root@u1804-docker-1:/# cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
root@u1804-docker-1:/#
root@u1804-docker-1:/# apt-get update
Get:1 http://mirrors.aliyun.com/ubuntu bionic InRelease [242 kB]
Get:1 http://mirrors.aliyun.com/ubuntu bionic InRelease [242 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB]
Get:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease [83.3 kB]
Get:5 http://mirrors.aliyun.com/ubuntu bionic/multiverse amd64 Packages [186 kB]
Get:6 http://mirrors.aliyun.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]
Get:7 http://mirrors.aliyun.com/ubuntu bionic/universe amd64 Packages [11.3 MB]
Get:8 http://mirrors.aliyun.com/ubuntu bionic/main amd64 Packages [1344 kB]
Get:9 http://mirrors.aliyun.com/ubuntu bionic-security/universe amd64 Packages [1635 kB]
Get:10 http://mirrors.aliyun.com/ubuntu bionic-security/restricted amd64 Packages [1668 kB]
Get:11 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages [3358 kB]
Get:12 http://mirrors.aliyun.com/ubuntu bionic-security/multiverse amd64 Packages [23.8 kB]
Get:13 http://mirrors.aliyun.com/ubuntu bionic-updates/restricted amd64 Packages [1709 kB]
Get:14 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages [3771 kB]
Get:15 http://mirrors.aliyun.com/ubuntu bionic-updates/universe amd64 Packages [2407 kB]
Get:16 http://mirrors.aliyun.com/ubuntu bionic-updates/multiverse amd64 Packages [30.8 kB]
Get:17 http://mirrors.aliyun.com/ubuntu bionic-backports/universe amd64 Packages [20.6 kB]
Get:18 http://mirrors.aliyun.com/ubuntu bionic-backports/main amd64 Packages [64.0 kB]
Fetched 28.0 MB in 8s (3574 kB/s)
Reading package lists... Done
root@u1804-docker-1:/#
root@u1804-docker-1:/# apt install vim -y
root@u1804-docker-1:/# apt install openssh-server -y
配置ssh
root@u1804-docker-1:/# service ssh status
* sshd is not running
root@u1804-docker-1:/# service ssh start
* Starting OpenBSD Secure Shell server sshd [ OK ]
root@u1804-docker-1:/#
root@u1804-docker-1:/# service ssh status
* sshd is running
root@u1804-docker-1:/#
设置密码123456
root@u1804-docker-1:/# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@u1804-docker-1:/#
查看IP
root@u1804-docker-1:/# hostname -I
172.17.0.2
root@u1804-docker-1:/#
修改 ssh 配置
参考 https://blog.csdn.net/frdevolcqzyxynjds/article/details/105282343
允许 root 用户远程(默认禁用root远程)
root@u1804-docker-1:/# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
重启 ssh 服务
root@u1804-docker-1:/# service ssh restart
* Restarting OpenBSD Secure Shell server sshd [ OK ]
root@u1804-docker-1:/#
root@u1804-docker-1:/#
Ctrl - D退出容器
ssh远程连接测试
[root@docker bin]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab45f34db2e2 ubuntu:18.04 "/bin/bash" 11 minutes ago Up 11 minutes 0.0.0.0:10022->22/tcp u1804-d1
[root@docker bin]#
[root@docker bin]# ssh root@172.17.0.2
The authenticity of host '172.17.0.2 (172.17.0.2)' can't be established.
ECDSA key fingerprint is SHA256:ZOgsnVUOvON+wr4yaNKLu/EVHGA7a29hyr7eQvBbeE4.
ECDSA key fingerprint is MD5:8a:ad:7e:4e:4a:13:05:f3:22:cb:fd:5d:fc:40:c8:19.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.0.2' (ECDSA) to the list of known hosts.
root@172.17.0.2's password:
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 3.10.0-862.el7.x86_64 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
root@u1804-docker-1:~#
我们下期见,拜拜!