【Docker】1.Docker的前身LXC

LXC

简介:Linux Containers ,一种操作系统层虚拟化技术,为Linux内核容器功能的一个用户空间接口。将应用软件系统打包成一个软件容器内涵应用软件本身的代码,操作系统核心和库。透过Namespace和Cgroup来分配不同软件容器的可用硬件资源。也就是Doker的前身

LXC Actual Conbat
lxc-checkconfig  						# 检查系统环境是否满足容器使用需求
lxc-create -n Name -t Templage_name       # 创建lxc容器
lxc-start -n Name -d 					# 启动容器
lxc-ls -f 							    # 列出所有容器 -f 打印常用信息
lxc-info -n Name 						# 查看容器相关信息
lxc-attack --name=Name[--Command]	      # 进入容器执行命令 
lxc-stop -n Name 						# 停止容器
lxc-destory -n Name 					# 删除处于停机状态的容器

安装和卸载

# 卸载
# 一、检查是否安装。清理资源
systemctl status lxc #检查是否安装
lxc-stop -n xxx # lxc-ls -f 遍历所有容器,停止对应的容器
lxc-destroy -n xxx #删除对应的容器
# 二、 卸载软件
yum remove lxc lxc-templates lxc-libs lxc-extra libvirt 
debootstrap 
# 三、检查,提示服务不存在
systemctl status lxc

# 安装
yum -y install lxc lxc-templates bridge-utils lxc-libs libcgroup libvirt lxc-extra debootstrap

# 启动和检查
systemctl start lxc #启动 lxc 服务
systemctl start libvirtd #启动虚拟机监控服务
systemctl status lxc 
systemctl status libvirtd

LXC 模板

[root@VM-20-6-centos templates]# ls /usr/share/lxc/templates
lxc-alpine     lxc-busybox  lxc-debian    lxc-gentoo        lxc-oracle  lxc-ubuntu
lxc-altlinux   lxc-centos   lxc-download  lxc-openmandriva  lxc-plamo   lxc-ubuntu-cloud
lxc-archlinux  lxc-cirros   lxc-fedora    lxc-opensuse      lxc-sshd


LXC创建容器

[root@VM-20-6-centos templates]# lxc-create -t ubuntu --name lxchost1 -- -r xenial -a amd64
-t 指定模板 --name 指定主机名 -- 设置主机内部参数  -r型号 -a CPU架构

##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##
# 创建完成会告诉我们默认用户为ubuntu,密码也是ubuntu,用ssh进行连接


[root@VM-20-6-centos templates]# lxc-ls -f 				# 查看虚拟机状态
NAME      STATE    IPV4  IPV6  AUTOSTART  
----------------------------------------
lxchost1  STOPPED  -     -     NO         

下载安装完所有软件包之后,LXC容器镜像就创建完成了。容器会被放到/var/lib/lxc/<容器名>/rootfs 目录下.创建下载的软件包会被保存在/var/cache/lxc目录中,如果想要另外建一个一样的容器时,可以省下很多的下载时间


LXC连接容器

[root@VM-20-6-centos templates]# lxc-ls -f   			 # 查看容器信息
NAME      STATE    IPV4  IPV6  AUTOSTART  
----------------------------------------
lxchost1  STOPPED  -     -     NO         
[root@VM-20-6-centos templates]# lxc-start -n lxchost1 -d  # 启动容器
[root@VM-20-6-centos templates]# lxc-ls -f
NAME      STATE    IPV4            IPV6  AUTOSTART  
--------------------------------------------------
lxchost1  RUNNING  192.168.122.72  -     NO         

方法1:使用ssh进行连接

[root@VM-20-6-centos templates]# ssh ubuntu@192.168.122.72
The authenticity of host '192.168.122.72 (192.168.122.72)' can't be established.
ECDSA key fingerprint is SHA256:tBKagxf+wL+8F65ec9OmR2zYHAuM1svMwEWW8AneW4M.
ECDSA key fingerprint is MD5:05:31:47:f6:4b:4b:52:39:04:8d:dc:9e:78:a4:cd:61.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.122.72' (ECDSA) to the list of known hosts.
ubuntu@192.168.122.72's password: 
Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 3.10.0-1160.62.1.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.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@lxchost1:~$ ls /
ubuntu@lxchost1:~$ df -h   # 查看挂载信息
ubuntu@lxchost1:~$ ps -ef

方法2:使用lxc-attach指令

[root@VM-20-6-centos templates]# lxc-attach -n lxchost1 --clear-env -- /bin/bash
root@lxchost1:/# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@lxchost1:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        59G   24G   33G  42% /
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G   12M  1.8G   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
root@lxchost1:/# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 07:04 ?        00:00:00 /sbin/init
root        22     1 98 07:04 ?        00:19:18 /lib/systemd/systemd-journald
root        23     1  0 07:04 ?        00:00:00 /lib/systemd/systemd-udevd
root        93     1  0 07:04 ?        00:00:00 /usr/sbin/cron -f
syslog      95     1  0 07:04 ?        00:00:00 /usr/sbin/rsyslogd -n
root       170     1  0 07:04 ?        00:00:00 /sbin/dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp
root       198     1  0 07:04 lxc/console 00:00:00 /sbin/agetty --noclear --keep-baud console 115200 38400 9600 l
root       199     1  0 07:04 ?        00:00:00 /usr/sbin/sshd -D
root       237     0  0 07:23 ?        00:00:00 /bin/bash
root       249   237  0 07:24 ?        00:00:00 ps -ef

LXC来完成容器创建,可以了解到docker并不是容器的唯一实现。现如今docker基本上都已经时使用libcontainer而非LXC了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白在进击

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值