docker和openssh

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

  1. root账户登陆 su root
  2. yum安装更新 yum update
  3. 安装软件包 yum install -y yum-utils device-mapper-persistent-data lvm2
  4. 查看docker版本 yum list docker-ce --showduplicates | sort -r
  5. 安装指定docker版本 yum install docker-ce-17.12.ce 17.12.ce为版本号
  6. 启动docker systemctl start docker
  7. 把docker加入开机启动 systemctl enable docker
  8. 验证是否安装成功 docker version
    若出现有client和service两部分表示docker安装启动成功了

Docker安Ubuntu16.04

  1. 使用docker pull 命令来从仓库获取所需要的镜像:docker pull ubuntu:16.04
  2. 查看已安装镜像:docker images
  3. 创建容器:docker run -t -i ubuntu:16.04 /bin/bash

    tips:

    1. 查看正在运行的容器:docker ps;查看所有容器:docker ps -a
    2. 运行容器docker start 容器名
    3. 进入容器docker exec -it 容器ID /bin/bash
    4. 删除容器docker rm 容器ID;删除镜像docker rmi 镜像ID
  4. 修改root密码:passwd,会显示Enter new UNIX password:,并需再次确认。(Mark:改成了1234567890)
    成功后会提示passwd: password updated successfully

Something Wrong

  1. 输入:# docker run -t -i docker.io/ubuntu:16.04 /bin/bash
    反馈:WARNING: IPv4 forwarding is disabled. Networking will not work.,但仍然进入容器成功。
    解决:

    1. vi /usr/lib/sysctl.d/00-system.conf
    2. vi内添加net.ipv4.ip_forward = 1
    3. ESC + “:” + “wq” 保存退出
    4. 重启network服务:systemctl restart network
    5. 删除原容器docker rm 容器id,再创建新容器。
  2. (废弃)后续操作需要用到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然后就可以了!

  3. (废弃)问题:yum找不到openssh软件包。且yum repolist all得到repolist: 0反馈。
    问题点:挂载yum源时中间断开连接。
    解决:keke网上找的全部没用,mount指令找不到路径,rpm甚至连yum版本也看不了。所以重新创个容器嗷。然后发现,是因为yum是centos用的(x,ubuntu默认软件包管理器是dpkg。所以老实一点用apt-get install下载。

OpenSSH安装

参考:https://www.cnblogs.com/hslzju/p/5839913.html

  1. 安装server服务:apt-get install openssh-server(想通过ssh被连接)
    PS.ubuntu自带openssh-clients,不需要另外下载。若出现安装问题参考“something wrong"(1)的第二条,update即可。

  2. 安装vim,方便更改apt-get install vimapt-get install vim-gnome

  3. 进入cd /etc/ssh,并vim sshd_config,修改配置。
    其中:PermitRootLogin prohibit-password改为 PermitRootLogin yes#PasswordAuthentication yes 去掉#。
    PS.
    #PermitRootLogin yes #允许root用户以任何认证方式登录(用户名密码认证和公钥认证)
    #PermitRootLogin without-password #只允许root用公钥认证方式登录
    #PermitRootLogin no #不允许root用户以任何认证方式登录

  4. cd进入后service ssh start
    显示Starting OpenBSD Secure Shell server sshd [ OK ]

localhost登陆

  1. cd .. 返回上级目录,ifconfig获得docker的内网地址(inet addr):172.17.0.2,并退出容器exit
  2. 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)

  1. exit退出容器(346563d1d522),显示
    logout
    Connection to 172.17.0.2 closed.

端口映射登陆

  1. 启动容器时,选择一个端口映射到容器内部开放端口上。
    docker run -ti -d --name try -p 3277:22 ubuntu:16.04
  2. 其余步骤相同,退出容器。
  3. ifconfig查看宿主机ipinet 192.168.122.1
  4. ssh -p 3277 root@192.168.122.1即可进入。
  5. 退出容器(b0d27f3b56d6)。

公钥认证登陆(待续)

  1. 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

  2. 进入容器进行安装,vim配置时有差异:cd /etc/sshvim sshd_config
    PermitRootLogin prohibit-password改为PermitRootLogin without-password
    #AuthorizedKeysFile %h/.ssh/authorized_keys改为AuthorizedKeysFile %h/.ssh/authorized_keys
    #PasswordAuthentication yes改为PasswordAuthentication yes

  3. 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

  1. 步骤五中出现问题:bash: ifconfig: command not found
    解决:安装net-tools:apt install net-tools

  2. 步骤6中问题:ssh: connect to host 172.17.0.2 port 22: No route to host
    解决:(?)重启ssh服务service ssh restart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值