Docker's core and installation

博文结构
Docker镜像操作
Docker容器操作
Docker资源控制
Docker核心概念

What a .Docker that?

(1) Docker is open source tools running on Linux container application, is a lightweight "virtual machine"
Logo Design blue whales, whales can be seen as the host, the above container can be understood as isolated container each container contains its own applications.

Docker's core and installation

Difference (2) Docker and virtual machines

As a virtual way a lightweight, Docker compared with traditional virtual machine has significant advantages.

Docker's core and installation

Docker reason has many advantages, and Caozuoxitong virtualization own characteristics are inseparable. Traditional virtual machine needs additional hypervisor and virtual machine layer Caozuoxitong, while Docker container is implemented directly on Caozuojitong level virtualization,
as shown:

Docker's core and installation

(3) Docker usage scenarios

Now developers need to easily create applications running on cloud platforms must be independent of the underlying hardware, but also need anytime, anywhere access to these resources available, this is the Docker has to offer. Docker container technology can easily create a lightweight on a host for any application, portable, self-contained container. In this container packaged applications, meaning that simplifies the re-deployment, debugging these trivial duplication of work, greatly improved work efficiency.

.Docker two core concepts and installation
(1) Mirroring

Docker's Mirror (mage) is the basis for creating a container, similar to a snapshot of the virtual machine
can be understood as a Docker container oriented read-only template engine. For example, a mirror may be a complete CentOS operating system environment, called - a CentOS
mirror; can be one of the MySQL application installation, called a MySQL mirror, and so on.

(2) container

Dooker container (Container) running instances created from the image. It can be started, stopped and deleted. Each container you create is isolated, and do not be seen, can guarantee the security of the platform. The container can be seen as a simple version of Linux rings
territory, Docker use container to run and isolation applications.

(3) Warehouse

Docker仓库(Repository) 是用来集中保存镜像的地方,当创建了自己的镜像之后,可以使用push命令将它上传到公有仓库(Public) 或者私有仓库(Private), 这样一来当 下次要在另外一台机器上使用这个镜像时,只需要从仓库上拉取下来就可以了。

(4)安装Docker

主机有网的话可以直接安装,

配置yum

[root@localhost ~]# rm -rf /etc/yum.repos.d/*

[root@localhost ~]# vim /etc/yum.repos.d/a.repo
[aaa]
name=asd
baseurl=file:///media
gpgcheck=0
[root@localhost ~]# mount /dev/cdrom /media/

[root@localhost ~]# yum -y install docker

安装完成可以启动Docker,并设置开机自启

[root@localhost ~]# systemctl start docker

[root@localhost ~]# systemctl enable docker

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# docker version  //查看Docker版本
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      8633870/1.13.1
 Built:           Fri Sep 28 19:45:08 2018
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      8633870/1.13.1
 Built:           Fri Sep 28 19:45:08 2018
 OS/Arch:         linux/amd64
 Experimental:    false

分为服务端与客户端

三.Docker镜像操作

(1)搜索镜像(前提电脑有网)

[root@localhost ~]# docker search dhcp

INDEX       NAME                                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/networkboot/dhcpd                    Suitable for running a DHCP server for you...   43                   [OK]
docker.io   docker.io/joebiellik/dhcpd                     DHCP server running on Alpine Linux             15                   [OK]
docker.io   docker.io/gns3/dhcp                            A DHCP container for GNS3 using dnsmasq         3                    [OK]
docker.io   docker.io/instantlinux/dhcpd-dns-pxe           Serve DNS, DHCP and TFTP from a small Alpi...   2                    [OK]
docker.io   docker.io/ictu/dhcpd-tftpd                     dhcpd tftpd container                           1                    [OK]
docker.io   docker.io/marcelwiget/dhcptester               Simple dhcp client simula

(2)获取镜像

[root@localhost ~]# docker pull docker.io/network/dhcpd //下载上面最开头的dhcp

还有一种就是插入已经下载好的dhcp

Docker's core and installation

做成光盘插入到主机中

[root@localhost ~]# mount /dev/cdrom /media/
[root@localhost ~]# cd /media/
[root@localhost media]# ls
dhcp
[root@localhost media]# cp dhcp /
[root@localhost media]# 
[root@localhost /]# docker load < dhcp
fccbfa2912f0: Loading layer 116.9 MB/116.9 MB
e1a9a6284d0d: Loading layer 15.87 kB/15.87 kB
ac7299292f8b: Loading layer 14.85 kB/14.85 kB
a5e66470b281: Loading layer 5.632 kB/5.632 kB
a8de0e025d94: Loading layer 3.072 kB/3.072 kB
e2e29955c5aa: Loading layer  12.7 MB/12.7 MB
12e14fab4dd4: Loading layer 49.15 kB/49.15 kB
47bdfd3bbf39: Loading layer 4.096 kB/4.096 kB
Loaded image: docker.io/networkboot/dhcpd:latest

将镜像下载到本地

(3)查看镜像信息

[root@localhost /]# docker images
REPOSITORY                    TAG                 IMAGE ID //镜像ID            CREATED             SIZE
docker.io/networkboot/dhcpd   latest              6f98b6b9b486        19 months ago       125 MB
REPOSITORY:  镜像属于的仓库。
TAG:  镜像的标签信息,标记同一个仓库中的不同镜像。
IMAGE ID:   镜像的唯一ID号,唯一标识了该镜像。
CREATED:  镜像创建时间。
CREATED:  镜像创建时间。

[root@localhost /]# docker inspect 6f98b6b9b486 \查看镜像ID详细信息

镜像的详细信息中包括创建时间、系统版本.主机名.域名.用户.卷.标签.操作系统.设备ID等各种信息。

[root@localhost /]# docker tag docker.io/networkboot/dhcpd dhcp:dhcp 
第一个dhcp:名称
第二个dhcp:标签

(4)删除镜像

[root@localhost /]# docker rmi dhcp:dhcp
Untagged: dhcp:dhcp

四.Docker容器操作

容器是Docker的另一一个核心概念,简单来说,容器是镜像的一个运行实例,是独立运行的一个或一组应用及它们所必需的运行环境,包括文件系统、系统类库. shell 环境等。镜像是只读模板,而容器会给这个只读模板一个额外的可写层

(1)容器的创建与启动

[root@localhost /]# docker create -it docker.io/networkboot/dhcpd /bin/bash

e392026ddd186d01cbd3306acae15f2f197dc9874a84ea241d347c7fe20a0946

常用选项: -i表示让容器的输入保持打开: -t表示让Docker分配一个伪终端。

[root@localhost /]# docker ps -a  \\查看所有容器运行状态
CONTAINER ID        IMAGE                         COMMAND                  CREATED              STATUS              PORTS               NAMES
e392026ddd18        docker.io/networkboot/dhcpd   "/entrypoint.sh /b..."   About a minute ago   Created                                 elegant_goldwasser

输出信息显示容器的ID号.加载的镜像.运行的程序.创建时间、目前所处的状态、端口映射.容器名称等。其中状态-栏为Created表示当前的容器是新创建的并处于停止状态。

[root@localhost /]# docker start e392026ddd18   \\启动容器 ,上面的ID
e392026ddd18

容器启动后,可以看到容器状态一栏已经变为UP,表示容器已经处于启动状态。

(2)容器的运行与终止

[root@localhost /]# docker stop 容器的ID号

(3)容器的进入

[root@localhost /]# docker exec -it e392026ddd18 /bin/bash
root@e392026ddd18:/# 

用户可以通过所创建的终端来输入命令,通过exit命令退出容器.

root@e392026ddd18:/# ls
bin   core  entrypoint.sh  home  lib64  mnt  proc  run   srv  tmp  var
boot  dev   etc            lib   media  opt  root  sbin  sys  usr
root@e392026ddd18:/# exit
exit

(4) introduced into the container export
container is minimized, resulting in some of the commands are not available, so they are derived from the inside of the container to the local set, and then setting up the container can be introduced into.

Export orders are as follows:

[root@localhost /]# docker export e392026ddd18>/etc/dhcp/dhcpd.conf

Container ID number of digital chaos

The master guide profile dhcp out configuration,

Import command as follows:

[root@localhost /]# docker import /etc/dhcp/dhcpd.conf > e392026ddd18

Remove the container (5)
you can use a command has been terminated dockerrm container status delete.
Image may comprise a plurality of containers

[root@localhost /]# docker stop e392026ddd18   \\先停止
e392026ddd18
[root@localhost /]# docker rm e392026ddd18   \\再删除
e392026ddd18
[root@localhost /]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Five .Docker resource control

Cgroup is Controlgroup shorthand, is a mechanism to limit the use of Linux kernel to provide physical resources, these resources include CPU. Memory, blkio. Below these three aspects to talk about how to use Cgroup mechanism Docker is managed.

(1) limit the CPU usage rate

For example, the container 60ff4594cc73 to 20000 CPU usage, CPU usage is set to 20% is defined as:

[root@localhost ~]# echo 20000 &gt;/sys/fs/ cgroup/ cpu/ system. slice/docker-60ff4594cc73b5474477 636b25b41f 16e1 66a3606aed22 6522d420d0c296990d. scope/cpu . cfs_ quota _us

(2) multi-tasking pro rata share CPU

For example, three new vessels run A. B, C, the proportion of CPU resources is 1: 1: 2 can perform such:

[root@localhost /]# docker run -tid --cpu-shares 1024   +镜像A
[root@localhost /]# docker run -tid --cpu-shares 1024   +镜像B
[root@localhost /]# docker run -tid --cpu-shares 2048   +镜像C

Guess you like

Origin blog.51cto.com/14400213/2453357