docker里安装linux系统,基于零的Docker学习笔记2: 使用docker安装Linux

e8a40c99a7b8d3d145d47a2bc94bd6e9.png

我在上一个笔记中写道,我在debian中安装了docker并运行了hello-world的神奇命令,但是我还能做什么?哈,让我们开始吧!检查了docker版本,看来它比教程要新,而且我不知道添加了哪些新功能. 无论他如何,还是有点白,让我们一起玩吧!

root@instance-1:~# docker version

Client: Docker Engine - Community

Version: 19.03.1

API version: 1.40

Go version: go1.12.5

Git commit: 74b1e89

Built: Thu Jul 25 21:22:03 2019

OS/Arch: linux/amd64

Experimental: false

Server: Docker Engine - Community

Engine:

Version: 19.03.1

API version: 1.40 (minimum version 1.12)

Go version: go1.12.5

Git commit: 74b1e89

Built: Thu Jul 25 21:20:35 2019

OS/Arch: linux/amd64

Experimental: false

containerd:

Version: 1.2.6

GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb

runc:

Version: 1.0.0-rc8

GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f

docker-init:

Version: 0.18.0

GitCommit: fec3683

root@instance-1:~#

使用docker安装ubuntu

我还参考了笑老虎的文章,该文章首先安装了ubuntu,因为ubuntu比centos更为熟悉linux docker下载安装,说明如下:

4db62dda6e90ebabcf050107c1a25825.png

在短短一个小时内,从零基础的Docker-Xiaohu开始学习文章zhuanlan.zhihu.com/p/23599229

[root@xxx ~]# docker search ubuntu # 查看ubuntu镜像是否存在

[root@xxx ~]# docker pull ubuntu # 利用pull命令获取镜像

[root@xxx ~]# docker images # 查看当前系统中的images信息

root@instance-1:~# docker images

ubuntu latest 3556258649b2 4 days ago 64.2MB

hello-world latest fce289e99eb9 6 months ago 1.84kB

//吼吼,有意思,看到docker三大件里的image了,咋用它呢?

root@instance-1:~# docker run -it ubuntu:latest /bin/bash # 启动一个容器

root@f22588294012:/# ssh 172.17.0.1

bash: ssh: command not found

root@f22588294012:/# ifconfig

bash: ifconfig: command not found

root@f22588294012:/#

//用这个ubuntu的镜像来启动了一个容器,并且这个容器里运行了一个ubuntu linux系统,但是这个linux里没有ssh/ifconfig这个程序呢,没有咋整呢,当然是装一个了!

root@f22588294012:/# apt-get update

root@f22588294012:/# apt-get install -y openssh-server net-tools vim #安装常用的工具

root@f22588294012:/# ssh 172.17.0.1

root@instance-1:~# exit

root@f22588294012:/# # ssh到host成功,那host能不能ssh到ubuntu呢?

root@f22588294012:/# ifconfig

eth0: flags=4163 mtu 1500

inet 172.17.0.10 netmask 255.255.0.0 broadcast 172.17.255.255

ether 02:42:ac:11:00:0a txqueuelen 0 (Ethernet)

RX packets 2169 bytes 44377997 (44.3 MB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 1350 bytes 111537 (111.5 KB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

loop txqueuelen 1 (Local Loopback)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

//按顺序按ctrl+p然后ctrl+q挂起centos的容器回到host

root@instance-1:~# ssh 172.17.0.10

ssh: connect to host 172.17.0.10 port 22: Connection refused

root@instance-1:~#

//哼,ubuntu座位ssh server不听话啊,看来需要再次进到里面配置一下

root@instance-1:~# docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

f22588294012 ubuntu:latest "/bin/bash" 15 minutes ago Up 15 minutes sleepy_bhaskara

root@instance-1:~# docker attach f22588294012 #重新进入ubuntu

root@f22588294012:/# service ssh status #原来是sshd 服务没起来

* sshd is not running

root@f22588294012:/# service ssh start #起来试一下看看

* Starting OpenBSD Secure Shell server sshd [ OK ]

root@f22588294012:/# read escape sequence

root@instance-1:~# ssh 172.17.0.10

root@172.17.0.10's password:

Permission denied, please try again. #衰,还是不行,应该是sshd配置有问题

2. 为ubuntu配置ssh功能:

上一步已经可以通过ssh在ubuntu中托管debian,但是相反,ubuntu seat ssh服务器不能为ssh. 起来!

cf8c8b55055b75e993c837b9ee7e0769.png

root@instance-1:~# docker attach f22588294012

root@f22588294012:/# passwd #改下root用户的密码

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

root@f22588294012:/# vi /etc/ssh/sshd_config #这里面总共需要添加如下3行即可

Port 22

PermitRootLogin yes

PasswordAuthentication yes

root@f22588294012:/# service ssh restart #重启ssh服务

root@f22588294012:/# read escape sequence

root@instance-1:~# ssh 172.17.0.10

root@172.17.0.10's password:

Last login: Sat Jul 27 23:02:17 2019 from 172.17.0.1

root@f22588294012:~# #host ssh登录ubuntu成功啦!

3. 创建自己的唯一图像文件:

我想镜像已使用ssh ifconfig和其他服务配置的容器,以备将来使用,以便下次无需配置这些混乱的东西. 这需要docker commit命令!

root@instance-1:~# docker ps -a 查看所有容器

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

f22588294012 ubuntu:latest "/bin/bash" 43 minutes ago Up 43 minutes sleepy_bhaskara

root@instance-1:~# docker commit -m "ssh installed" -a "elaiz" f22588294012 elaiz/ubuntu:ssh

sha256:d4cbb2e508309a2d21c6b63abdaa1ee485b0e20ec3b08aca20d916895beb4160

root@instance-1:~# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

elaiz/ubuntu ssh d4cbb2e50830 About a minute ago 242MB

ubuntu latest 3556258649b2 4 days ago 64.2MB

本文来自电脑杂谈,转载请注明本文网址:

http://www.pc-fly.com/a/jisuanjixue/article-156494-1.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值