Detailed installation Docker

First, uncover the mystery of Docker
Docker is an open source tool for applications running in a Linux container is a lightweight "virtual machine" was born in 2013, just a few years, has become the most popular open source community s project.
.
So why would such a fire Docker it? Look at the diagram to know:
Detailed installation Docker

As a lightweight virtual machine mode, Docker compared with traditional virtual machine has significant advantages.
Docker reason has many advantages, and Caozuoxitong virtualization own characteristics are inseparable. Traditional virtual machine requires additional hypervisor and virtual machine layer Caozuojitong, while Docker container is implemented directly on the Caozuojitong level virtualization.
Detailed installation Docker
Docker usage scenarios
now require developers 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. Through this application packaged in containers, which means simplifying the re-deployment, debugging these trivial duplication of work, greatly improving the work efficiency. For example, Tencent server migration from cloud to cloud Ali, if Docker container technology, migration only need to start the container can be required on the new server.
Second, the core concept of Docker :
1. Mirror
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 for read-only template engine. For example, a mirror may be a complete CentOS Caozuoxitong environment, called a CentOS mirror; can be one of MySQL applications installed MySOL called a mirror, and so on..
Doacker provides a simple mechanism to create and update existing mirror image. the user can also download ready made applications directly from the internet using a mirror.
2. Container
Docker containers (Conainer! Is run from the mirrored instance is created, it can be started. Stop and delete each container you create is isolated from each other. And do not be seen, can guarantee the security of the platform can be put container as a simple version of the Linux environment, Docker use container to run and isolated applications.
3. warehouse
Docker repository (Repository) is used to centrally stored image of the place, when creating your own image, you can use the push command to upload it to a public warehouse (Pbli) or a private warehouse (Private), so in addition to the current minor when using this image on a single machine, pulling down on it just from the warehouse.
Warehouse registration server (Registry) local storage warehouse, which contains a plurality of warehouses, each warehouse and store a certain type of image, and using different tags (Tag) to distinguish them, the largest public repository is Docker Hb, store a huge number of images available for download.
Third, the installation Docker
under Centos system installation Docker There are two ways: one is to use curl to get Docker's installation script. Another is to use YUM repositories to install Docker.
Note: Currently Docker can only support 64-bit operating system
Note: Docker currently only support 64-bit operating system
Note: Docker currently only support 64-bit operating system
I use here is the Docker own YUM installation sources
to begin the installation:

[root@test /]# yum -y install docker             # 安装docker
[root@test /]# systemctl start docker              # 启动服务
[root@test /]# systemctl enable docker           # 设为开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Docker has installed two programs: Docker Docker server and client. Docker service process which manages all of the containers. Docker client will play Docker service side of the remote controller can be used to control the server process Docker's. In most cases, Docker service and client running on a single machine.

[root@test /]# docker version 
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 mirroring
requires the presence of former Docker containers running locally corresponding image, if there is no local mirror, Docker attempts from the default image warehouse https://hub.docker.com download at, this is a public official maintained by the Docker warehouse.
1. Search Mirror:

[root@test /]# docker search dhcp        # 命令格式 docker search 关键字
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]
...............      // 省略部分内容

2, takes a snapshot:
search conform to the image, you can use docker pull be downloaded to the local

[root@test /]# docker pull docker.io/networkboot/dhcpd
Using default tag: latest
Trying to pull repository docker.io/networkboot/dhcpd ... 
latest: Pulling from docker.io/networkboot/dhcpd
898c46f3b1a1: Downloading 5.602 MB/32.47 MB
63366dfa0a50: Download complete 
041d4cd74a92: Download complete 
6e1bee0f8701: Download complete 
114483241095: Downloading 3.693 MB/6.702 MB
ef446bdcb1f0: Waiting 

3, to view mirror information:

[root@test /]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
docker.io/networkboot/dhcpd   latest              52cbff801df2        8 months ago        105 MB
从回显的信息中可以读出:
REPOSITORY:镜像属于的仓库
TAG:镜像的标签信息,标记同一个仓库的不同镜像
IMAGE ID :镜像的唯一ID号,唯一标识了该镜像
CREATED:镜像创建时间
VIRTUAL SIZE:镜像大小

The unique identification may be the user ID number mirror, mirror for details:

[root@test /]# docker inspect 52cbff801df2
[
    {
        "Id": "sha256:52cbff801df2c6e2da3866d9f9476f20f190f64a0e886fbdfa79d843befa666a",
        "RepoTags": [
            "docker.io/networkboot/dhcpd:latest"
        ],
...............................  // 省略部分内容

For more information Mirror contains a variety of information creation time, the system version, host name, domain name, user, volume, label, operating system, device ID and so on.
For ease of use, add a new label for the local mirror:

[root@test /]# docker tag docker.io/networkboot/dhcpd  dhcp:dhcp
[root@test /]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
dhcp                          dhcp                52cbff801df2        8 months ago        105 MB
docker.io/networkboot/dhcpd   latest              52cbff801df2        8 months ago        105 MB

4, remove the mirror:

命令格式:
docker  rmi  仓库名称:标签
或者
docker rmi   镜像ID号

When docker rmi order to keep up with the mirror behind the ID number, must ensure that the image is not being used to carry out the container, the system will delete all point to the mirror when you remove the label, and then delete the image file itself. If the mirror has been used container, the correct approach is to delete all dependent on the mirror container, remove the mirror again.
5, the storage and loading mirror:
keep out

[root@test /]# docker save -o /tmp/dhcp docker.io/networkboot/dhcpd
[root@test /]# ll -d /tmp/dhcp 
-rw------- 1 root root 107891712 Nov 25 17:56 /tmp/dhcp

Loading

[root@test tmp]# docker load --input dhcp
[root@test tmp]# docker load < dhcp

6, upload image:
a local store out of the mirror more and more, you need to specify a special place to store these images - the warehouse is now more convenient public warehouses, the default upload DockerHub official repository, you need to register the use of public warehouses account, you can use the docker login command to enter a user name, password, and email to register and log in. Also you need to add a new label for a local mirror before uploading the image, and then use docker push to upload.
For example: on a public warehouse already registered an account, in this case account for the test, mirrored label Docker / dhcp: centos7.3
(1) the first to use the official repository account login:

[root@test /]# docker login 
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: test                       # 输入账号
Password:                               # 输入密码
Login  Succeeded

(2) after a successful landing can upload image:

[root@test /]# docker push docker/dhcp:centos7.3

Docker container operations
container Docker another core concept simple, the container is a running instance mirror, or a group of applications, and they must operate independently of the operating environment, including a file system, library system, the shell environment. Mirroring is a read-only template, and the vessel will give this a read-only template additional writable layer.
1, the container creation and startup:
Docker's process of creation is mirrored loaded into the container, Docker containers is very lightweight, the user can create or delete at any time. The newly created default container is stopped, do not run any program, in which the need to initiate a process to start container, this process is the only process the container, so when the end of the process, the container will be completely stopped. Stop the container can reboot and retain the original modification.

[root@test /]# docker create -it docker.io/networkboot/dhcpd /bin/bash           # 创建容器
08ab448cd0be320b24d6878b377bfa6957127c7ffb4c7e050e64340deeee1562
# -i 表示让容器的输入保持打开;-t 表示让Docker分配一个伪终端

If you create a container where the command error "WARNING: IPv4 forwarding is disabled.Networking will notwork.", Then use the vi editor to open /usr/lib/sysctl.d/00-system.conf file, add net.ipv4. ip_ forward = 1, and then restart the network service using the command service network start.

It returns a unique ID to create a new container after use docker create command.

[root@test /]# docker ps -a                 # 查看所有容器的运行状态        -a 可以列出系统最近一次启动的容器
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS               NAMES
08ab448cd0be        docker.io/networkboot/dhcpd   "/entrypoint.sh /b..."   5 minutes ago       Created                                 keen_payne
命令格式: docker   start   容器的ID/名称
[root@test /]# docker start 08ab448cd0be                # 可跟容器的ID与名称
08ab448cd0be
[root@test /]# docker ps -a | grep 08ab448cd0be 
08ab448cd0be        docker.io/networkboot/dhcpd   "/entrypoint.sh /b..."   8 minutes ago       Up About a minute                       keen_payne
# 容器启动后,可以看到容器状态一栏已经变成了 UP ,表示容器已经处于启动状态

2, run and stop the container:

[root@test /]# docker stop 08ab448cd0be
08ab448cd0be
[root@test /]# docker ps -a 
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS                     PORTS               NAMES
08ab448cd0be        docker.io/networkboot/dhcpd   "/entrypoint.sh /b..."   10 minutes ago      Exited (0) 5 seconds ago                       keen_payne
# 查看容器的运行状态,可以看出容器处于Exited,中止状态。

3, access to the container:

[root@test /]# docker exec -it 08ab448cd0be /bin/bash
#  -i 表示让容器的输入保持打开;-t 表示让Docker分配一个伪终端
root@08ab448cd0be:/# ls                  # 已经进入到了容器中
bin  boot  dev  entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@08ab448cd0be:/# exit
exit
[root@test /]# 

4, the container export and import:
a user may move from any of a Docker containers one machine to another machine. During the migration process, you first need to have created a good container export to a file, you can use docker export command to achieve, whether this container is in the running or stopped can be exported. After exporting the export file may be transferred to other machines, the container is achieved by migration of the corresponding import command.

命令格式:docker export  容器ID/名称>文件名
[root@test /]# docker export  08ab448cd0be>centos7dhcp
[root@test /]# ll -d centos7dhcp 
-rw-r--r-- 1 root root 87825920 Nov 25 19:58 centos7dhcp

A file replication derived from machine to machine B, then use the docker import command to import, the mirror becomes.

命令格式:cat    文件名 | docker  import   - 生成的镜像名称:标签
[root@test /]# cat centos7dhcp | docker import - centos7:dhcp
sha256:e7193f77c973a89dd2d1046f09eb4328798f4ee9dff92ad13514fb7268bc3c27
[root@test /]# docker images | grep centos7
centos7                       dhcp                e7193f77c973        17 seconds ago      84.7 MB

5, the container removed:

命令格式:docker  rm   容器ID/名称
[root@test /]# docker stop 08ab448cd0be
08ab448cd0be
[root@test /]# docker rm 08ab448cd0be
08ab448cd0be
[root@test /]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
# 如果删除一个正在运行的容器,可以添加 -f 选项强制删除,但是建议先将容器停止再做删除操作

Docker default directory is stored in / var / lib / docker, Docker mirror, the container, the contents of all logs stored in this partition may be used alone large capacity to store the content, and is generally selected to establish LVM logical volume, so as to avoid Docker in the process of running out of storage capacity problem directory.

Guess you like

Origin blog.51cto.com/14306186/2453830