【Docker】1.Docker的前身LXC

米饭6个月前行业资讯286

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












相关文章

大数据存储方案

大数据存储方案

1 结构布局目前大数据存储有两种方案可供选择:行存储和列存储。业界对两种存储方案有很多争持,集中焦点是:谁能够更有效地处理海量数据,且兼顾安全、可靠、完整性。从目前发展情况看,关系数据库已经不适应这种...

Docker背后的容器管理——Libcontainer深度解析

Docker背后的容器管理——Libcontainer深度解析

原文地址:http://www.infoq.com/cn/articles/docker-container-management-libcontainer-depth-analysisLibcont...

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

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

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

Linux 安装Docker完整教程(六)

Linux 安装Docker完整教程(六)

背景近些年随着云原生的发展,Docker在云原生中的作用使得它也蓬勃发展起来。今天这篇文章就带大家一起实现一下在Linux操作系统下Docker的部署过程,收藏起来,以备不时之需。当然,如果对Dock...

Linux 环境下Docker部署项目(七)

Linux 环境下Docker部署项目(七)

一、前言本文是讲述的是怎么样定义Dockerfile,然后在Docker中部署springboot项目。由于只是为了学习docker容器部署。因此本文基于的镜像只是基于单纯的java 8(由于官网弃用...

【Docker】0.空间资源隔离

【Docker】0.空间资源隔离

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

发表评论    

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