One sentence summary:
Docker is the container principle: such as isolation: Docker provides a set of application packaging, transmission and deployment methods. So that you can better run any application inside the container. Docker is a portable application container
Docker can quickly create various environments: such as Node.js website server, API server, database, etc.
1. What are the benefits of docker?
1-1. Quickly build an isolation environment: Different applications may have different application environments. For example, websites developed by .net and websites developed by php rely on different software. If If the software they rely on is installed on a server, it will take a long time to debug, which is very troublesome and will cause some conflicts. For example, there is a conflict between IIS and Apache access ports. At this time, you need to isolate the website developed by .net and the website developed by PHP. Generally speaking, we can create different virtual machines on the server and place different applications on different virtual machines, but the virtual machine overhead is relatively high. Docker can realize the function of virtual machine isolation application environment, and the overhead is smaller than that of virtual machines. Small size means saving money.
1-2. Encapsulate the development environment and solve the environment version problem: When you develop the software, you use Ubuntu, but the operation and maintenance management is centos. The operation and maintenance is transferring your software from the development environment to In the production environment, you will encounter some problems when converting Ubuntu to CentOS. For example, there is a special version of the database that is only supported by Ubuntu but not by CentOS. During the transfer process, operation and maintenance must find ways to solve such problems. If you have docker at this time, you can directly encapsulate and transfer the development environment to operation and maintenance, and operation and maintenance can directly deploy the docker you gave him. And it’s fast to deploy.
1-3. Memory utilization: In terms of server load, if you open a virtual machine alone, the virtual machine will occupy free memory. If Docker is deployed, this memory will be utilized.
2. What is docker? What can docker do?
The idea of Docker comes from containers. What problems do containers solve? On a large ship, cargo can be arranged neatly. And all kinds of goods are standardized by containers, and containers will not affect each other. Then I don’t need a ship specifically for carrying fruits and a ship specifically for carrying chemicals. As long as these goods are packed well in the container, then I can transport them all on a big ship.
docker is a similar concept. Cloud computing is now popular, and cloud computing is like a big freighter. Docker is a container.
2-1. Different applications may have different application environments. For example, a website developed by .net and a website developed by php rely on different software. If the software they depend on is installed in one Debugging on the server takes a long time, is very troublesome, and may cause some conflicts. For example, there is a conflict between IIS and Apache access ports. At this time, you need to isolate the website developed by .net and the website developed by PHP. Generally speaking, we can create different virtual machines on the server and place different applications on different virtual machines, but the virtual machine overhead is relatively high. Docker can realize the function of virtual machine isolation application environment, and the overhead is smaller than that of virtual machines. Small size means saving money.
2-2. When you develop software, you use Ubuntu, but the operation and maintenance management is centos. Operation and maintenance will encounter some problems when transferring your software from the development environment to the production environment. Problems with converting Ubuntu to CentOS, for example: there is a special version of the database that is only supported by Ubuntu but not by CentOS. During the transfer process, operation and maintenance must find ways to solve such problems. If you have docker at this time, you can directly encapsulate and transfer the development environment to operation and maintenance, and operation and maintenance can directly deploy the docker you gave him. And it’s fast to deploy.
2-3. In terms of server load, if you open a virtual machine alone, the virtual machine will occupy free memory. If Docker is deployed, this memory will be utilized.
In short, docker is the container principle.
3. What can developers use docker for?
Docker has gained a lot of attention nowadays, and many people find it hard to live up to its reputation because they still don’t understand what the relationship between Docker and ordinary developers is. Many developers feel that Docker is far away from them. Docker is a tool in the production environment and has nothing to do with them. It also took me a long time to figure out how to use Docker in my own development as an ordinary developer. Frankly, I'm still in the learning process.
This article provides a list of Docker use cases. I hope it can better help you understand Docker and trigger your thinking. This article only describes the daily application of Docker by ordinary developers and does not provide a complete solution.
Before introducing the use cases, I hope you can remember this sentence: "Docker is a portable application container." You don’t have to know what Docker means by “portable container”, but you must know that Docker can bring huge efficiency improvements in daily life.
When you need to run your own application in a container (of course it can be any application), Docker provides a basic system image as the basic system for running the application. In other words, any application on a Linux system can run in Docker.
Can I run the database in Docker? sure.
Can I run the Node.js website server inside Docker? sure.
Can I run the API server in Docker? sure.
Docker doesn’t care what your application is or does. Docker provides a set of application packaging, transmission and deployment methods so that you can better run any application within a container.
4. Try new software
For developers, all kinds of new technologies that are born every day need to be tried. However, development However, it is unlikely that the developer will set up the environment and conduct testing for them one by one. Time is precious, and thanks to Docker, it is possible for us to set up the environment in one or a few commands. Docker has a fool-proof method of obtaining software. The Docker background will automatically obtain the environment image and run the environment.
Docker is not just used for new technology environment construction. If you want to quickly run a MySQL database or a Redis message queue on your laptop, you can do it very easily using Docker. For example, Docker only needs one command to run the MySQL database:
docker run -d -p 3306:3306 tutum/mysql。
Translator's Note: Although the MySQL database can be installed very quickly using commands, when the latest technology or very complex technology is used, use Docker will be a very good choice, such as Gitlab. It takes an average user about a day to build the Gitlab platform, but Docker only requires one command.
5. Learn linux scripts
Of course this reason may seem strange, but for those who are not familiar with the Linux operating system and Shell scripts It is indeed a good opportunity for people. Even though this article is not about Linux, the importance of Linux is still self-evident. If you are using Windows, then let me give you a suggestion: rent a cloud host from a cloud hosting provider: I recommend using a CoreOS system cloud host. Although this will not make you a professional Linux operation and maintenance, it will allow you to quickly learn the basics of Linux, fall in love with command line operations, and slowly start to become familiar with and appreciate Linux.
6. Better utilization of resources
The granularity of the virtual machine is "virtualized machine", while the granularity of Docker is "restricted" Application", in comparison, Docker takes up less memory and is more lightweight.
For me, this is an advantage of Docker: because I often run multiple Docker applications on my computer, using Docker is simpler and more convenient than using a virtual machine, has finer granularity, and can continuously track the status of the container.
7. Customize for microservices
If you have been paying attention to technology news, then you should have heard of the concept of "Microservices". Docker can be combined well with microservices. Conceptually, a microservice is a container that provides part of a complete set of application functionality, and Docker can serve as a microservice container during development, testing, and deployment. Even production environments can deploy microservices in Docker.
8. Porting between cloud service providers
Most cloud hosting providers already fully support Docker. For developers, this means that you can easily switch cloud service providers. Of course, you can also easily move your local development environment to a cloud host. There is no need to configure the running environment locally and configure it on the cloud host. Also configure the running environment once. Comprehensive deployment of Docker (Docker here and Docker there) as a standard operating environment can greatly reduce the workload and generate bugs when the application is online.
9、API
API is the glue between applications. A qualified developer must have used REST APIs provided by others, or developed REST APIs himself. It should be pointed out that whether it is the client or the API provider, before development, a set of public API interfaces need to be defined and documented before coding. If the server and client are jointly developed, the server will usually first implement an API interface that can return a fixed string, and then slowly implement the API functions in future development.
Although some people may think that Docker has been abused here, and you can use files like sample.json to implement virtual APIs, there is an example below that can better solve the API problem when developing front-end and back-end separation.
To better explain what I mean, let me give you an example: JSON Server, a REST API for providing JSON data. Anyone who has used this container will know that since there is such an easy-to-use Docker JSON Server, we have no reason not to use Docker.
For more related questions, please visit the PHP Chinese website: PHP Video Tutorial
The above is the detailed content of Super detailed analysis of the principles and functions of php docker. For more information, please follow other related articles on the PHP Chinese website!