【Docker】1.Docker的前身LXC

米饭2个月前行业资讯68

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了

本文系转载,版权归原作者所有,如若侵权请联系我们进行删除!  

云掣基于多年在运维领域的丰富时间经验,编写了《云运维服务白皮书》,欢迎大家互相交流学习:

《云运维服务白皮书》下载地址:https://fs80.cn/v2kbbq

想了解更多大数据运维托管服务、数据库运维托管服务、应用系统运维托管服务的的客户,欢迎点击云掣官网沟通咨询:https://yunche.pro/?t=shequ












相关文章

Spring AOP 实战指南:从入门到精通(3)

Spring AOP 实战指南:从入门到精通(3)

3.3 @PointCut:Spring 提供了 @PointCut 注解,把公共的切点表达式提取出来,需要用到时引用该切入点表达式即可,便于后续代码的维护。@Aspect @Slf4j @Com...

一个初级运维工程师对于运维工作的一些浅显认知

一个初级运维工程师对于运维工作的一些浅显认知

最近因为部门架构调整,之前工作做了交接,新的安排又没有确定,领导建议学习下JAVA开发,后续直接参与到研发工作中而不再负责运维工作。周围同事也都在说运维工作比较low,转研发会好一些。但是毕竟从毕业之...

【Docker】0.空间资源隔离

【Docker】0.空间资源隔离

NameSpacedd + option : 可以从标准输入或文件中读取数据,根据指定格式来转换数据,再输出到文件、设备或标准输出 --help 显...

【Docker 】深入探索 Docker :高阶操作与配置设置(上)

【Docker 】深入探索 Docker :高阶操作与配置设置(上)

Docker 是现代应用开发和部署的重要工具,能够帮助开发者轻松创建、管理和部署容器化应用。除了基本的命令外,掌握高阶操作和配置设置将大大提高您的工作效率和应用性能。本文将介绍一些 Docker 的高...

什么是 SRE?一文详解 SRE 运维体系

什么是 SRE?一文详解 SRE 运维体系

可观测性系统在任何有一定规模的企业内部,一旦推行起来整个SRE的运维模式,那么对于可观测性系统的建设将变得尤为重要,而在整个可观测性系统中,通常我们会分为如下三个方面:指标监控:即各种指标监控,比如基...

Docker 常用命令

Docker 常用命令

 一、Docker 基础命令1、启动 dockersystemctl start docker2、关闭 dockersystemctl stop docker3、重启 dockersyste...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。