Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction and use of Docker container

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The knowledge points of this article include: the introduction of Docker container, the advantages of Docker container, the core concept of Docker container and the use of Docker container. Read the complete article, I believe you have some understanding of Docker container.

A brief introduction to Docker

The official website www.docker.com

Github https://github.com/docker/docker.github.io

The open source container engine allows developers to package applications and dependent libraries and release them to any popular linux distribution for easy migration.

It is written by go language and released based on apache2.0 protocol.

Based on linux kernel, it is necessary to use a vm (virtual machine) to run under win.

Since 2013, it has developed rapidly in recent years.

Starting from 1.13x, docker is divided into community version ce and enterprise version ee, and based on the timeline of the year and month, for example, 18.03 is March 2018, and the current stable version is 18.09 reference.

Docker version change description: http://blog.csdn.net/chenhaifeng2016/article/details/68062414

Comparison of Docker and traditional virtualization:

Docker, also known as container virtualization, is also lightweight virtualization because it lacks a layer of operating system.

The bottom layer is the server, the hardware, the upper layer is the host OS,Linux operating system, and then up, there is a traditional Hypervisor, such as KVM, which needs to install a KVM service to drive virtualization, and docker needs to install a docker service. The third layer is similar, and then it is different. Docker does not need to install a guest virtual machine, while the traditional virtual machine needs to be built after installing KVM. Install another operating system on this virtual machine.

Advantages of Docker

The startup is very fast and can be realized in seconds.

Resource utilization is high, and a highly configured server can run thousands of docker containers.

Faster delivery and deployment, once created and configured, can be run anywhere.

Kernel-level virtualization, which does not require additional hypevisor support, will have higher performance and efficiency. Services that do not need to virtualize CPU, memory, and so on.

Easy to migrate, platform dependence is not strong. You can create an image under Linux and run it under Windows.

The following figure shows a comparison of the characteristics of docker and virtual machines:

The core idea of Docker

Image, is a read-only template, similar to the iso file used to install the system, we use images to complete the deployment of various applications.

Container, the image is similar to the operating system, and the container is similar to the virtual machine itself. It can be started, started, stopped, deleted, and so on, and each container is isolated from each other.

Warehouse, a place where images are stored, the warehouse is divided into public warehouse and private warehouse. The largest open warehouse is Docker hub (hub.docker.com), the domestic open warehouse (dockerpool.com).

Second, install Docker

Download an official yum source first

# curl https://download.docker.com/linux/centos/docker-ce.repo-o / etc/yum.repos.d/docker.repo# yum list | grep docker-ce can see that the latest version is 19.03docker-ce.x86_64 3etc/yum.repos.d/docker.repo# yum list 19.03.5-3.el7 docker-ce-stable# yum install-y docker-ce

The speed is relatively slow, or you can download the rpm package directly.

Https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

Download and upload to linux

It also needs to be installed with yum, which can automatically resolve dependencies

# yum install-y docker-ce-xxxx.rpm# systemctl start docker starts docker

After startup, it will automatically generate some iptables rules for you, but this rule will not be saved automatically. To save it, execute service iptables save. Generally, as a server for docker, iptables rules try not to touch it.

# iptables-t nat-F# iptables-t nat-nvL# systemctl restart docker# iptables-t nat-nvL after clearing the rule and restarting docker, the rule will come back, but it must be saved first.

III. Mirror management

Similar to the iso image file of the system.

# docker pull centos / / you can download centos images at a very slow speed. Go directly to the official website to pull an image.

Docker pull is similar to git pull.

Configure the docker Accelerator (see http://blog.csdn.net/xlemonok/article/details/71403534)

# vi / etc/docker/daemon.json// add the following {"registry-mirrors": ["https://dhq9bx4f.mirror.aliyuncs.com"]}"

Note: this url is the address of the accelerator and you need to apply to Aliyun on your own.

After configuring the accelerator and restarting the docker service, docker pull centos will be much faster again.

Docker images View the local image [root@fuxi01 ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos latest 0f3e07c0138f 3 months ago 220MB

TAG: tags. Each image can have many tags. Latest this is the version label.

IMAGE ID: used to distinguish the ID of each mirror in the system, and the unique identification of the image.

# docker search xxx / / which images are officially available? use search to search for images, where xxx is the keyword, such as jumpserver Will label the jumpserver-related docker# docker tag centos yw_centos / / to the image # docker tag centos centos:111 # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEubuntu latest 549b9b86cb8d 13 days ago 64.2MByw_centos latest 0f3e07c0138f 3 months ago 220MBcentos 111l 0f3e07c0138f 3 months ago 220MBcentos latest 0f3e07c0138f 3 months ago 220MB

If you don't add a colon, the label is in the first column, followed by a colon, followed by a mark in TAG, and the second column.

# docker run-itd centos 43aae89a76aef04cab62efcf6c4ec2f24a29f69db192125b0d72b2e111af69ba

/ / docker run starts the image as a container.-I means to open the standard input of the container.-t means to assign a pseudo terminal.-d means to start in the background. Put-I-t-d in front of the image name.

# docker ps / / View the containers that are running. Add the-an option to view all containers, including those that are not running, docker ps-a. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES43aae89a76ae centos "/ bin/bash" About a minute ago Up 24 seconds serene_kare# docker rmi centos # docker rmi centos:111Untagged: centos:111

/ / it is used to delete the specified image. Rm is to delete, and I is images. The latter parameter can be tag. If it is tag, it actually deletes the tag. When the latter parameter is Mirror ID, the entire image will be deleted completely, and all tags will be deleted together. When there is an image with the same name, but the tag is different, you need to add the tag to delete it.

4. Docker creates an image through the container

After docker run is started as a container, you can enter the container with the following command

# docker exec-it 43aae89 bash# docker exec-it infallible_lalande bash

/ / where 43aae89 is the container id, and this id can be viewed with docker ps or write its names without writing the container ID. You can see in docker ps that the bash on the last side is the command to be executed after entering the container, so you can open a terminal.

Go into the container, make some changes, such as installing something, and then create a new image for the container.

Execute yum install-y net-tools in the container, then ctrl d exits the container, and ifconfig can see the network card with docker0.

# docker commit-m "change somth"-a "somebody info" container_id new_image_name

/ / container_id is obtained through docker ps-a, and the following new_image_name is the name of the new image.

For example:

# docker commit-m "install net-tools"-a "aminglinux" 43aae89 centos_with_net

This command is a bit like the submission of svn,-m plus some change information,-a specifies the author information, the 43aae89 string is the container id, followed by the name of the new image.

# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos_with_net latest 2803335f23a6 33 seconds ago 261MBubuntu latest 549b9b86cb8d 3 weeks ago 64.2MBcentos latest 0f3e07c0138f 3 months ago 220MByw_centos latest 0f3e07c0138f 3 months ago 220MB

Execute docker images to see the new image.

After reading the above, do you have any further understanding of Docker containers? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report