Docker entry _ PHP Tutorial

Source: Internet
Author: User
Tags docker hub docker registry
Get started with docker. This article is originally written by fireaxe. you can copy and repost docker with the help of GPL. However, for reprinting, please maintain the integrity of the document and indicate the original author and original link. The content can be used freely. get started with docker

This article was originally published by fireaxe and can be freely copied and reproduced using GPL. However, for reprinting, please maintain the integrity of the document and indicate the original author and original link. The content can be used at will, but no guarantee is made for the consequences caused by the use of the content.

Author: haoqiang1531@outlook.com blog: fireaxe.blog.chinaunix.net
1. what is docker? in principle, docker is a technology derived from lxc and AUFS. Q: What is lxc? A: lxc is A linux kernel container, which is equivalent to A linux lightweight virtual machine. Compared with virtual machine with virtual box, vmware, and other instruction set virtualization, the advantage of virtual machine is to use the kernel of the host system. Therefore, lxc can be viewed as a virtual machine that shares the kernel. The disadvantage of lxc is that the kernel of the host is used to run the linux system in the INER. To use a non-linux system, you can only use virtual machines such as vmware. Q: What scenarios do I need to use docker? It is best to read the following content before discussing this issue. However, based on the importance of this issue, I decided to move it to the previous section. (In general, most of them only look at the first three paragraphs ...) 1) cloud deployment (this part has never been played, but it can only be heard). Previously, virtual machines were used. with docker, some applications that do not require any operating systems were used, immediately moved over. Of course, lxc works, but all applications that use the cloud platform are large-scale applications. Lxc does not have the ease of deployment and migration required for large-scale applications. 2) the Company's internal CI platform is the establishment of the CI platform. docker technology can be used to separate various CI platform tools to improve the flexibility of upgrade. At the same time, tools are backed up using the image method. (Another method for data backup) 2. package the test environment and use dockerfile to automatically use the latest version to synthesize a testing environment to eliminate environmental interference. At the same time, once the test is complete, you can release an image to avoid various configuration problems caused by the customer's re-installation of the software. (In the past, we had to adapt to various environments. now we are ready to release together with the environment, so we don't need to test multiple environments.) 3) quickly build a development environment using docker to implement the development environment, once someone has a new computer and wants to build a development environment, they can use pull to get an image and get it done in minutes !!
Q: Why can lxc be isolated? A: In fact, the principle of linux startup is to first start the kernel, and the kernel starts the user space. In this case, it is not impossible for the kernel to start multiple user spaces. All you need is to isolate the kernel. This is also the reason why lxc needs to be implemented in the kernel. the user space does not necessarily need to know that there are other user spaces besides itself)
Q: Why can different releases run in the container of a system at the same time? A: The main difference between linux releases is that user space and kernel are the same, which also facilitates simultaneous running of different releases. Lxc only provides kernel for the container, and then constructs different user spaces according to the needs of different releases.
Q: Since lxc already provides container, why not use lxc directly? A: Actually, docker is not used everywhere. it depends on the application scenario. Lxc is essentially a virtual machine technology. if I usually work for different releases or different versions of the unified release, lxc is enough. Docker is more like splitting services. Today's systems are getting more and more complex, and running on the same machine may interfere with each other. It is not conducive to migration. if you want to migrate a service to another machine, you may encounter various environment configuration and dependency problems. This can also be used with lxc, but since each container of lxc only supports kernel, the user-mode environment needs to be reconfigured. If apache server is required for all three containers, I need to install them once in each container, which is obviously a waste. Or if the gcc compiler is required for different development environments, install multiple copies. So some people started to reuse some of the user space's attention.
Q: How can I reuse user space? A: docker is based on lxc and AUFS. AUFS allows users to reuse some of their userspaces. User space is essentially a file system. Therefore, the reuse of user space can be viewed as the reuse of file systems. AUFS can stack multiple directories and separately set the read/write attributes of each directory. To put it simply, lxc generates a file system completely isolated from the outside for each container. in this way, from the perspective of user space, we are the only operating system. On this basis, AUFS implements stacking, allows multiple containers to share part of the file system. Q: What is the significance of file system sharing implemented by AUFS? A: For example, I want to use two containers, mysql server and redmine server. The operating system must be ubuntu. On lxc, I need to construct two containers containing ubuntu, and then install the two software respectively. On docker, you can first construct a ubuntu container, and then construct two container based on the container for mysql server and server respectively. Ubuntu is read-only for its derived INER. Then, if you find that you need to add several applications based on mysql one day, you can easily dispatch the container from mysql server. In this way, the reuse is realized by means of derivation. For more details, refer to: 10 images to give you a deep understanding of Docker containers and images ( http://dockone.io/article/783 ) Q: What is the difference between image and container? A: Actually, the image is A container, and the image is equivalent to A read-only copy of the container. If the sub-INER directly reuse the parent container, when the sub-container modifies the content of the parent container, other sub-container of the parent container will be affected. Therefore, the parent container is made into a read-only image, so that its sub-container cannot be modified. On the other hand, the container is dynamic. similar to a set of code managed in git, the image is equivalent to a commit (the command for generating an image from the container in docker is exactly a commit ). The container can only be used by developers. only after you use commit to generate an image can other talents pull out branch for parallel development. Of course, after commit, the image only exists locally. if you want collaborative development by multiple people, you also need to use the "docker push" command to push the image to the server. Docker servers are called docker registry.
Q: What is dockerfile? A: dockerfile is the script used to generate an image and is usually used for deployment in the production environment. Example 1: I developed a set of software, and a docker image needs to be released every week. The normal process is to use pull as a basic image, download and install my software, and then commit it into a new image for release. With dockerfile, I can automate this process. each time I run a docker build command, I use the compiled dockerfile to generate a new image. Example 2: a production environment depends on multiple components, but these components are constantly updated. If you use an image, you need to package and resend the image after each update. With dockerfile, it is much better. every time you need to update the environment, you only need to run dockerfile again. it automatically downloads and installs the latest components according to the command. In summary, we emphasize the role of a dockerfile: a scripting language that automates the packaging process of the environment. The development process does not play a major role.
2. common commands
Command Explanation
Create [-- name container-id] Create a INER based on the specified image
Start [-ti/-d/-v] Start the specified INER iner
-Ti establishes virtual terminal disease connection
-D: run in the background, and do not exit after the command is complete
-V maps the host directory to the container
Run [-- name container-id] 'Docker create' + 'docker start'
Ps [-a] In the running container
-A: All container
Iamges [-a] All images
-A: All images and layers that constitute the image
History An image and its layers
Stop Container shutdown
Pause Container pause
Rm Delete container
Commit Create a new image based on the container
Rmi Delete an image
Pull Contract step: specify image to local
Push Integrate the image to the docker hub
Login Log on to docker hub

3. docker routine this directly refer to the following link: http://docs.docker.com/mac/started/
4. data volume and data volume container (data volume & data volume container) 1) significance of data volume and data volume container data volume: implement data and application separation. Data is not included in the actual application backup. Data is backed up separately. Because data and application backup usually require different policies.
The data volume container uses the data volume container to isolate the actually used host. In this way, when the data location on the host changes, you only need to modify the data volume container. other application containers do not need to be modified.
2) use a data volume to create a container containing a data volume: $ docker run-v/data/path:/mount/path: ro -- name dbdata ubuntu/bin/bash create a container containing two volumes: $ docker run-d-v/data/path1:/mount/path1: ro-v/data/path2:/mount/path2: ro -- name dbdata ubuntu/bin/bash $ docker run-ti -- volumes-from dbdata -- name app ubuntu
Use-v to mount the host directory "/data/path" to the "/mount/path" directory of container dbdata. Dbdata becomes a data volume container. The actual container app is generated based on dbdata. Use "-- volumes-from dbdata" to obtain the read and write permissions of the data volume container dbdata.

This article was originally published by fireaxe and can be freely copied and reproduced using GPL. However, for reprinting, please maintain the integrity of the document and indicate the original author and original link. The content can be used at will, but no guarantee is made for the consequences caused by the use of the content.

Author: Haoqiang1531@outlook.com blog: fireaxe.blog.chinaunix.net

Http://www.bkjia.com/PHPjc/1068090.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1068090.htmlTechArticledocker entry this article is fireaxe original, use GPL release, can freely copy, reprint. However, for reprinting, please maintain the integrity of the document and indicate the original author and original link. The content can be used at will ,...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.