不知道到底要干嘛的docker
Centos7 系统安装
参考:https://jingyan.baidu.com/article/8ebacdf0762b0249f65cd53b.html
非常重要(与参考有出入)
官网下载DVD版:
http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso
千万不要用阿里源!
阿里源下载实测无法安装,CentOS7检测不到磁盘文件,且不是个例。
清华源可用。
划分磁盘时,boot请多分一点!200m完全不够用。
Docker安装
参考:https://www.cnblogs.com/qgc1995/archive/2018/08/29/9553572.html
- root账户登陆
su root
- yum安装更新
yum update
- 安装软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
- 查看docker版本
yum list docker-ce --showduplicates | sort -r
- 安装指定docker版本
yum install docker-ce-17.12.ce
17.12.ce为版本号 - 启动docker
systemctl start docker
- 把docker加入开机启动
systemctl enable docker
- 验证是否安装成功
docker version
若出现有client和service两部分表示docker安装启动成功了
Docker安Ubuntu16.04
- 使用docker pull 命令来从仓库获取所需要的镜像:
docker pull ubuntu:16.04
- 查看已安装镜像:
docker images
- 创建容器:
docker run -t -i ubuntu:16.04 /bin/bash
tips:
- 查看正在运行的容器:
docker ps
;查看所有容器:docker ps -a
- 运行容器
docker start 容器名
- 进入容器
docker exec -it 容器ID /bin/bash
- 删除容器
docker rm 容器ID
;删除镜像docker rmi 镜像ID
- 查看正在运行的容器:
- 修改root密码:
passwd
,会显示Enter new UNIX password:
,并需再次确认。(Mark:改成了1234567890)
成功后会提示passwd: password updated successfully
Something Wrong
-
输入:
# docker run -t -i docker.io/ubuntu:16.04 /bin/bash
反馈:WARNING: IPv4 forwarding is disabled. Networking will not work.
,但仍然进入容器成功。
解决:vi /usr/lib/sysctl.d/00-system.conf
- vi内添加
net.ipv4.ip_forward = 1
- ESC + “:” + “wq” 保存退出
- 重启network服务:
systemctl restart network
- 删除原容器
docker rm 容器id
,再创建新容器。
-
(废弃)后续操作需要用到yum,安装
apt-get install yum
,显示错误如下:Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package yum问题点:执行命令前更换了软件源,未update。
解决:apt-get update
然后就可以了! -
(废弃)问题:yum找不到openssh软件包。且
yum repolist all
得到repolist: 0
反馈。
问题点:挂载yum源时中间断开连接。
解决:keke网上找的全部没用,mount指令找不到路径,rpm甚至连yum版本也看不了。所以重新创个容器嗷。然后发现,是因为yum是centos用的(x,ubuntu默认软件包管理器是dpkg。所以老实一点用apt-get install
下载。
OpenSSH安装
-
安装server服务:
apt-get install openssh-server
(想通过ssh被连接)
PS.ubuntu自带openssh-clients,不需要另外下载。若出现安装问题参考“something wrong"(1)的第二条,update即可。 -
安装vim,方便更改
apt-get install vim
及apt-get install vim-gnome
-
进入
cd /etc/ssh
,并vim sshd_config
,修改配置。
其中:PermitRootLogin prohibit-password
改为PermitRootLogin yes
、#PasswordAuthentication yes
去掉#。
PS.
#PermitRootLogin yes #允许root用户以任何认证方式登录(用户名密码认证和公钥认证)
#PermitRootLogin without-password #只允许root用公钥认证方式登录
#PermitRootLogin no #不允许root用户以任何认证方式登录
-
cd
进入后service ssh start
显示Starting OpenBSD Secure Shell server sshd [ OK ]
localhost登陆
cd ..
返回上级目录,ifconfig
获得docker的内网地址(inet addr):172.17.0.2,并退出容器exit
ssh root@172.17.0.2
,反馈如图,成功进入容器。(有warning待解决)
[root@localhost /]# 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:hxdkXbN63wnGcfeJNgsB2+RXL+MsRBg3qInhYS/jY6c.
ECDSA key fingerprint is MD5:3e:2a:92:5e:fc:b8:86:e1:a0:64:eb:eb:03:2d:b4:ff.
Are you sure you want to continue connecting (yes/no)? y
Please type ‘yes’ or ‘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 16.04.6 LTS (GNU/Linux 3.10.0-957.el7.x86_64 x86_64)
- Documentation: https://help.ubuntu.com
- Management: https://landscape.canonical.com
- Support: https://ubuntu.com/advantage
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.
- exit退出容器(346563d1d522),显示
logout
Connection to 172.17.0.2 closed.
端口映射登陆
- 启动容器时,选择一个端口映射到容器内部开放端口上。
docker run -ti -d --name try -p 3277:22 ubuntu:16.04
- 其余步骤相同,退出容器。
ifconfig
查看宿主机ipinet 192.168.122.1
ssh -p 3277 root@192.168.122.1
即可进入。- 退出容器(b0d27f3b56d6)。
公钥认证登陆(待续)
-
docker run -tid -p 22 -P ubuntu:16.04
再查看,得到CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
23867fa8e56e ubuntu:16.04 “/bin/bash” 40 seconds ago Up 38 seconds 0.0.0.0:32768->22/tcp adoring_curie -
进入容器进行安装,vim配置时有差异:
cd /etc/ssh
,vim sshd_config
PermitRootLogin prohibit-password
改为PermitRootLogin without-password
#AuthorizedKeysFile %h/.ssh/authorized_keys
改为AuthorizedKeysFile %h/.ssh/authorized_keys
#PasswordAuthentication yes
改为PasswordAuthentication yes
-
ssh-keygen -t rsa
,一直回车,生成宿主机的密钥如下:
The key fingerprint is:
SHA256:BumHXZz5QGGH9FPDh86tGMXJgl/pj1x/uWJnIVKbBMs root@localhost.localdomain
The key’s randomart image is:
±–[RSA 2048]----+
| .=+.+o+ |
| . +o*…X…|
| o B.=B o |
| . + . Eo++ o|
| o S ++o=o|
| o …++o+|
| . . +|
| o + |
| . + |
±—[SHA256]-----+
4.cd /root/.ssh
Something Wrong
-
步骤五中出现问题:
bash: ifconfig: command not found
解决:安装net-tools:apt install net-tools
-
步骤6中问题:
ssh: connect to host 172.17.0.2 port 22: No route to host
解决:(?)重启ssh服务service ssh restart