Docker container management tools
Author: Yin Zhengjie
Copyright: original works, declined to reprint! Otherwise held liable.
Earlier we introduced the chroot, namespace and cgroups, with these three Linux built-in module constitutes a good base of container operating environment, but also need to have the appropriate container creation and deletion of management tools, and how to put the vessel up and running, how data container treatment, such as startup and shutdown problems to be solved, so container management technology emerged. At present, the use of docker container management tools, there are early use lxc container management tools.
A .Linux Container (referred LXC)
1> What is LXC
LXC Linux Container Linux is shorthand. We can provide lightweight virtualization, while isolate processes and resources. Bloggers Recommended reading: HTTPS: // linuxcontainers.org/
2> .Ubuntu installation tool lxc
root@docker101:~# apt-get -y install lxc lxd Reading package lists... Done Building dependency tree Reading state information... Done lxd is already the newest version (3.0.3-0ubuntu1~18.04.1). lxd set to manually installed. The following additional packages will be installed: libpam-cgfs lxc-utils Suggested packages: lxc-templates lxctl The following NEW packages will be installed: libpam-cgfs lxc lxc-utils 0 upgraded, 3 newly installed, 0 to remove and 71 not upgraded. Need to get 390 kB of archives. After this operation, 1,316 kB of additional disk space will be used. Get:1 http://mirrors.aliyun.com/ubuntu bionic-updates/universe amd64 libpam-cgfs amd64 3.0.3-0ubuntu1~18.04.1 [29.8 kB] Get:2 http://mirrors.aliyun.com/ubuntu bionic-updates/universe amd64 lxc-utils amd64 3.0.3-0ubuntu1~18.04.1 [357 kB] Get:3 http://mirrors.aliyun.com/ubuntu bionic-updates/universe amd64 lxc all 3.0.3-0ubuntu1~18.04.1 [2,968 B] Fetched 390 kB in 0s (807 kB/s) Selecting previously unselected package libpam-cgfs. (Reading database ... 67286 files and directories currently installed.) Preparing to unpack .../libpam-cgfs_3.0.3-0ubuntu1~18.04.1_amd64.deb ... Unpacking libpam-cgfs (3.0.3-0ubuntu1~18.04.1) ... Selecting previously unselected package lxc-utils. Preparing to unpack .../lxc-utils_3.0.3-0ubuntu1~18.04.1_amd64.deb ... Unpacking lxc-utils (3.0.3-0ubuntu1~18.04.1) ... Selecting previously unselected package lxc. Preparing to unpack .../lxc_3.0.3-0ubuntu1~18.04.1_all.deb ... Unpacking lxc (3.0.3-0ubuntu1~18.04.1) ... Processing triggers for ureadahead (0.100.0-21) ... Setting up libpam-cgfs (3.0.3-0ubuntu1~18.04.1) ... Setting up lxc-utils (3.0.3-0ubuntu1~18.04.1) ... Created symlink /etc/systemd/system/multi-user.target.wants/lxc-net.service → /lib/systemd/system/lxc-net.service. Created symlink /etc/systemd/system/multi-user.target.wants/lxc.service → /lib/systemd/system/lxc.service. Setting up lxc dnsmasq configuration. Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Setting up lxc (3.0.3-0ubuntu1~18.04.1) ... root@docker101:~# root@docker101:~#
3>.检查内核对lxc的支持情况
root@docker101:~# lxc-checkconfig Kernel configuration not found at /proc/config.gz; searching... Kernel configuration found at /boot/config-4.15.0-74-generic --- Namespaces --- Namespaces: enabled Utsname namespace: enabled Ipc namespace: enabled Pid namespace: enabled User namespace: enabled Network namespace: enabled --- Control groups --- Cgroups: enabled Cgroup v1 mount points: /sys/fs/cgroup/systemd /sys/fs/cgroup/blkio /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/rdma /sys/fs/cgroup/freezer /sys/fs/cgroup/memory /sys/fs/cgroup/devices /sys/fs/cgroup/cpuset /sys/fs/cgroup/perf_event /sys/fs/cgroup/pids /sys/fs/cgroup/hugetlb /sys/fs/cgroup/net_cls,net_prio Cgroup v2 mount points: /sys/fs/cgroup/unified Cgroup v1 clone_children flag: enabled Cgroup device: enabled Cgroup sched: enabled Cgroup cpu account: enabled Cgroup memory controller: enabled Cgroup cpuset: enabled --- Misc --- Veth pair device: enabled, loaded Macvlan: enabled, not loaded Vlan: enabled, not loaded Bridges: enabled, loaded Advanced netfilter: enabled, not loaded CONFIG_NF_NAT_IPV4: enabled, loaded CONFIG_NF_NAT_IPV6: enabled, not loaded CONFIG_IP_NF_TARGET_MASQUERADE: enabled, loaded CONFIG_IP6_NF_TARGET_MASQUERADE: enabled, not loaded CONFIG_NETFILTER_XT_TARGET_CHECKSUM: enabled, loaded CONFIG_NETFILTER_XT_MATCH_COMMENT: enabled, not loaded FUSE (for use with lxcfs): enabled, not loaded --- Checkpoint/Restore --- checkpoint restore: enabled CONFIG_FHANDLE: enabled CONFIG_EVENTFD: enabled CONFIG_EPOLL: enabled CONFIG_UNIX_DIAG: enabled CONFIG_INET_DIAG: enabled CONFIG_PACKET_DIAG: enabled CONFIG_NETLINK_DIAG: enabled File capabilities: Note : Before booting a new kernel, you can check its configuration usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig root@docker101:~# root@docker101:~#
4>.下载容器
root@docker101:~# ll /usr/share/lxc/templates/ #存放模板的脚本文件 total 60 drwxr-xr-x 2 root root 4096 Aug 5 19:24 ./ drwxr-xr-x 6 root root 4096 Jan 12 15:03 ../ -rwxr-xr-x 1 root root 8370 Nov 23 2018 lxc-busybox* -rwxr-xr-x 1 root root 18155 Nov 23 2018 lxc-download* #该脚本说明需要下载官方的模板。 -rwxr-xr-x 1 root root 7175 Nov 23 2018 lxc-local* #该脚本说明使用本地的模板 -rwxr-xr-x 1 root root 10649 Nov 23 2018 lxc-oci* root@docker101:~# root@docker101:~# lxc-create -t download --name my_alpine2020 -- --dist alpine --release 3.9 --arch adm64 温馨提示: -t: 指定模板名称,我们这里指定download模板,就会调用"/usr/share/lxc/templates/lxc-download"脚本,该脚本说明我们目前没有自己的模板,需要下载官方的模板。 --name: 指定容器名称,即为创建的容器命名。 --: 用来说明后面的参数是传递给download脚本的,告诉脚本需要下载什么养的模板。 --dist: 操作系统名称,即指定操作系统。 --release: 指定操作系统的发行版本。可以是各种Linux的变种。 --arch: 指定交媾,是x86还是arm,是32位还是64位。
5>.管理lxc容器命令
root@docker101:~# lxc-start my_alpine2020 #启动lxc容器 root@docker101:~# root@docker101:~# lxc-attach my_alpine2020 #进入lxc容器 root@docker101:~#
6>.lxc启动容器依赖于模板
lxc启动容器依赖于模板,清华模板源: https://mirrors.tuna.tsinghua.edu.cn/help/lxc-images/ 但是做模板相对较难,需要手动一步步构建文件系统,准备基础目录及可执行程序等,而且在大规模使用容器的场景很难横向扩展,另外后期代码升级也需要重新从头构建模板,基于以上种种原因便有了docker容器管理工具。
二.docker
docker启动一个容器也需要一个外部模板但是较多镜像,docker的镜像可以保存在一个公共的地方共享使用,只要把镜像下载下离开就可以使用,最主要的是可以在镜像基础之上做自定义配置并且可以再把其提交为一个镜像,一个镜像可以被启动为多个容器。
docker的镜像是分层的,镜像底层为库文件且只读不能写入也不能删除数据,从镜像加载启动为一个容器 后会生成一个可写成,其写入的数据会复制到容器目录,但是容器内的数据在删除容器后默认也会被随之删除。
三.pouch
2017年11月19日上午,在中国开源年会现场,阿里巴巴正式开源了基于Apache 2.0协议的容器技术Pouch。Pouch是一款轻量级的容器技术,拥有快速高效、可移植性高、资源占用少等特性,主要帮助阿里更快的做到内部业务的交付,同时提高超大规模下数据中心的物理资源利用率。 博主推荐阅读: https://github.com/alibaba/pouch https://www.infoq.cn/article/alibaba-pouch