Resources
Http://baijiahao.baidu.com/s?id=1585063200948693359&wfr=spider&for=pc
52343910
Https://www.cnblogs.com/heyanan/p/7800284.html
A docker overview
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 publish them to any popular Linux distribution, which is handy for porting. Written by the go language, based on the APACHE2.0 protocol release, based on the Linux kernel, to run under win requires the use of a VM (virtual machine) to achieve. It has been developing rapidly in recent years since 2013. Docker starts with the 1.13x, the version is divided into the community version of CE and Enterprise Edition EE, and based on the time line format, the latest stable version of the current 17.09 reference http://blog.csdn.net/chenhaifeng2016/article/details/68062414
Comparison of two Docker with traditional virtualization
Traditional virtual machine technology is virtual out of a set of hardware, on the virtual hardware running an operating system, virtual machine applications in the Guest OS run. The application of the Docker container runs directly on the host, and the container has no virtual hardware or its own kernel, and is a lightweight virtualization technology. As you can see from the comparison, Docker's Docker Engine layer replaces the Hypervisor layer and Guest OS layer in the virtual machine.
The core of virtualization is the abstraction of resources, and the goal is often to run multiple systems or applications on the same machine, thus increasing the utilization of system resources. Virtualization is divided into many types, such as common hardware-assisted virtualization (VMware Workstation, KVM, and so on). The container virtualization technology represented by Docker is operating system-level virtualization: The kernel isolates different processes by creating multiple virtual operating system instances (cores and libraries).
Traditional virtualization and container technology structure comparison: The traditional virtualization technology is virtualized at the hardware level, which increases the link of the system call link, has the performance loss; container virtualization technology is implemented in a shared kernel, with little performance loss.
It can be understood that we do not consider the final application software, the traditional virtual language needs four layers of structure, and Docker only need three layers.
Traditional virtualization,
Bottom: Hardware physical machine
Second tier: Host operating system. Like WinDOS.
Layer Three: Hypervisor refers to the virtualization of hardware resources. Can be a KVM vmvare
Layer Fourth: Virtual machine operating system, such as CentOS
Docker
Lowest layer: Hardware physical machine
Second tier: Host operating system
Tier Three: Docker engine
Benefits of Docker
Start very fast, second-level implementations
High resource utilization, one high-configuration server can run thousands of Docker containers
Faster delivery and deployment, once created and configured, you can run build Once,runanywhere anywhere
Kernel-level virtualization with no additional hypevisor support for higher performance and efficiency
Easy migration, not strong platform dependencies
The core concept of three Docker
1 mirroring
Image, is a read-only template, similar to the ISO file used by the installation system, we use mirroring to complete the deployment of various applications. A mirror can contain only one operating system environment (such as the SuSE image), or the user program and its operating environment (such as a ebackup mirror) can be installed. A mirror is actually a file, and any user program can be part of the image.
Mirroring = Operating system + software operating environment + user program
2 Containers:
A container is a running instance created from a mirror that can be started, started, stopped, deleted, and so on, and each container is isolated from each other. If the image can be likened to a class, the container is the object after the image is instantiated. The container is what we use directly to manipulate, he is concrete, dynamic. And the mirror is abstract and static.
3 Warehouses
A place where the image is stored and the warehouse is divided into public warehouses and private warehouses. The largest public warehouse is the Docker hub (hub.docker.com), the domestic public warehouse (dockerpool.com)
Four Docker basic operations
1 Docker Installation
curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker.repo
Yum Install-y Docker-ce
Speed is slow, you can also download the RPM package directly
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
Download finished, upload to Linux
Also needs to be installed with Yum to automatically resolve dependencies
yum install -y docker-ce-xxxx.rpmsystemctl start docker 启动docker
2 Docker Image Management
docker pull centos
Download CentOS image
docker images
View a local mirror
docker search xxx
Search image, where xxx is the key word
docker tag centos lv
Label the image
docker run -itd centos
Start the image as a container,-I means to let the container's standard input open,-t for assigning a pseudo-terminal,-D for background start, to put-i-t-D to the mirror name before
docker ps
View the running container, plus the-a option to view all containers, including the non-running
docker rmi centos
Used to delete the specified image, where the following argument can be tag, and if it is tag, the tag is actually deleted. When the following parameter is the mirror ID, the entire image is completely deleted and all tags are deleted together
3 Docker creates mirrors through containers
After the Docker run starts the container, you can enter the container with the following command
docker exec -it xxxxx bash
Where xxxxx is the container ID, this ID can be viewed with Docker PS, the last bash is the command we want to execute after entering the container, so we can open a terminal
Into the container, we make some changes, such as installing something, and then creating a new image for the container
Execute the Yum install-y net-tools in the container and then ctrl d to exit the container
docker commit -m "change somth" -a "somebody info" container_id new_image_name //container_id通过docker ps -a获取,后面的new_image_name为新镜像名字
For example: Docker commit-m "Install Net-tools"-a "LV" 2c74d574293f centos_with_nettool This command is a bit like svn commit,-m plus some change information,-a specify author related information 2c7 4d This string is the container ID, followed by the name of the new mirror
4 docker creating mirrors using templates
First go to download a template
http://openvz.org/Download/templates/precreated//Download a centos6 template centos-6-x86-minimal.tar.gz
wget https://download.openvz.org/template/precreated/centos-6-x86-minimal.tar.gz
Address will be changed, please go to the official website to find the appropriate link.
The commands to import the image are:
cat centos-6-x86-minimal.tar.gz|docker import - centos6
docker images
View the imported Mirrors
Export the existing image to a file:
docker save -o centos6.tar centos6
-O followed by file name and mirror name
We can also restore the local image with this file:
docker load --input centos6.tar
Or
docker load < centos6.tar
docker push image_name
You can upload your own image to Dockerhub official website, if you need to register a user first
5 Docker Container Management
docker create -it centos6 bash
This allows you to create a container, but the container does not start
docker start container_id
After starting the container, you can use Docker PS to see that there is a stop on start, and restart
Previously we used a Docker run equivalent to create and start
docker run -it centos bash
This enters a virtual terminal, we can run some commands, exit the Bash with command exit or CTRL d, and the container will stop when it exits.
Docker run-d allows containers to run in the background
Like what:docker run -d centos bash -c "while :; do echo "123"; sleep 2; done"
docker run --name web -itd centos bash
--name Custom names for containers
docker run --rm -it centos bash -c "sleep 30"
--RM can be removed after the container exits, where the command finishes executing the container will exit
docker logs
You can get the run history information to the container using the following
docker logs container_id
docker attach
Can enter a container running in the background, such as
docker attach container_id
But the attach command is not easy to use, for example, we want to exit the terminal, we have to exit, so the container will also exit, there is a way
docker exec -it container_id bash
Can temporarily open a virtual terminal, and after exit, the container is still running
docker rm container_id
CONTAINER_ID is PS when the check see, so that you can remove container, if it is a running container, you can add-f
docker export container_id > file.tar
Export containers that can be migrated to other machines and need to be imported
cat file.tar |docker import - test
This will generate a mirror of test
Bulk Close and Delete containers
docker ps -a | awk ‘{print $1}‘|xargs docker stopdocker ps -a | awk ‘{print $1}‘|xargs docker rm
6 Docker Warehouse Management
docker pull registry
Download registry image, Registy is an image of Docker, which we can use to create a local Docker private repository.
docker run -d -p 5000:5000 registry
Start the container in registry mirror,-P will map the port of the container to the host, the left is the host listening port, the right is the container listening port
curl 127.0.0.1:5000/v2/_catalog
can access it
Now let's upload one of the mirrors to the private repository.
docker tag centos 192.168.56.132:5000/centos6
Tag the tag, you must have a private warehouse with the Ip:port
Where CentOS is the mirror name
docker push 192.168.56.132:5000/centos6
Push the tagged image to the private repository
This does not succeed at this time, the following prompt appears
Get https://192.168.56.132:5000/v2/: Http:server gave HTTP response to HTTPS client
Change the configuration file,vi /etc/docker/daemon.json
Change to
{ "insecure-registries":["192.168.56.132:5000"] }
Note: Changed the HTTP access path for the warehouse. The default is the public warehouse.
systemctl restart docker
docker ps -a
Check that the container is closed and you need to start
docker start id
Here the ID is registry container ID
Push again
docker push 192.168.56.132:5000/centos6
curl 127.0.0.1:5000/v2/_catalog
You can view the images that were pushed up
7 The difference between Docker export save
Exporting (export)
The Export command is used to persist the container (not mirroring). Therefore, we need to get the container ID by the following methods:
sudo docker ps-a
Then perform the export:
Docker export <container id> >/home/export.tar
Saving (Save)
The Save command is used to persist the image (not the container). Therefore, we need to get the image name by the following methods:
sudo docker images
Then execute the Save:
sudo docker save busybox-1 >/home/save.tar
Images that are exported and then imported (exported-imported) will lose all history, and the image saved and Reloaded (saveed-loaded) does not lose its history and layers (layer). This means that you will not be able to roll back to the previous layer (layers) using the export and then import, and then you can roll back the entire image using the Save and reload mode (you can perform Docker tag <layer id> <image NAME > Roll back to the previous layer).
Through the experiment we can learn that import imported files are exported from the export template. Export exports are operated on containers.
The file loaded by load is the image saved by save. Save saves the hour to manipulate the image. These two sets of commands cannot be confused.
Five Docker specific applications
So much for that, where is Docker going to use it? The answer is from a netizen called Crazy Einstein.
For example, you use Ubuntu, the server is CentOS, then you have to deploy the project to the server, it may be in the configuration of the environment will take a lot of time. Or, for example, if you use MySQL, put it in a previous system or a different environment, you will have to reload your environment, the more things spend more time.
With Docker, you only need one command, and you can run a "new environment" on your Ubuntu, which is based on your existing environment, which means that you're actually sharing the same set of resources, but you've got what you need in this environment.
If you need MySQL, install a mirror with MySQL and start a container.
If you need Redis, install a mirror with Redis and start a container.
You need ..., then ..., then ....
Of course, you can also be on the basis of others, the container modified, such as adding some of your own software or modify the configuration file, and then commit, so you make this container into a mirror, you can use this image to create a container of n identical.
For example, if you want to learn to carry a Redis cluster, then you can download a Redis image, then start the container, set up the cluster configuration, commit the container to generate the image, and then run 6 or more containers based on the image, so that a cluster is built up.
And Docker occupies a small amount of resources.
Linux Learning Summary (69) Docker-1