【Docker】1.Docker的前身LXC

米饭4个月前行业资讯164

LXC

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

LXC Actual Conbat
C++
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 					# 删除处于停机状态的容器

安装和卸载

C++
# 卸载
# 一、检查是否安装。清理资源
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 模板

C++
[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创建容器

C++
[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连接容器

C++
[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进行连接

C++
[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指令

C++
[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







阅读剩余的60%

相关文章

Gartner权威报告解读|应用可观测性列为2023年重要战略技术趋势!

Gartner于今日发布企业机构在2023年需要探索的十大战略技术趋势。Gartner杰出研究副总裁Frances Karamouzis表示:“为了在经济动荡时期增加企业机构的盈利,首席信息官和IT高...

Docker——Windows版本Docker安装

Docker——Windows版本Docker安装

一、简介一、简介  1.1 Docker如何解决大型项目依赖关系复杂,不同组件依赖的兼容性问题?Docker允许开发中将应用、依赖、函数库、配置一起打包,形成可移植镜像Docker应用运行在...

Docker:namespace隔离实战

Docker:namespace隔离实战

namespacenamespace通过一种内核技术来实现,允许将不同的系统资源隔离和封装到独立的命名空间中。为容器化、虚拟化和隔离提供强大的基础。通过使用namespace技术,Linux内核可以创...

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

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

三、Spring AOP 详解3.1 Spring AOP 核心概念:3.1.1 切点(Pointcut):切点(Pointcut),也称之为"切入点"。Pointcut 的作用就...

Docker容器——网络模式和Cgroup资源限制

Docker容器——网络模式和Cgroup资源限制

一、Docker网络(1)Docker网络实现原理Docker使用Linux桥接,在宿主机虚拟一个Docker容器网桥(docker0),Docker启动一个容器时会根据Docker网桥的网段分配给容...

MyBatisPlus从零到一:快速入门与核心功能详解(5)

MyBatisPlus从零到一:快速入门与核心功能详解(5)

3.4 通用枚举:MybatisPlus 提供了一个处理枚举的类型转换器,可以帮我们把枚举类型与数据库类型自动转换。3.4.1 创建枚举对象并添加 @EnumValue 注解要让MybatisPlus...

发表评论    

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