Code in or out of Docker

The first thing that needs to be clear is: what kind of benefits can Docker bring, and the advantages that Docker brings in terms of lightweight virtualized containers (high resource utilization, fast creation, and pure environment)  ? Or the advantages that images bring (easy deployment, logging container state, continuous integration, etc.) ?   Determine the use of the scene, just to explain where the code is more appropriate.

 

To name a few examples, code and data can be used in flexible ways depending on the scenario:

 

Scenario 1: If you have completed all the code and want to distribute it to other users, it is best to put this code in the image, including the database initialization script, etc.

 

Scenario 2: If it is a development environment, the code is used for debugging, the code should not be in the image, the code should preferably be on the local computer, such as MacOS, Windows, Linux personal PC, then mount it by volume It is the most convenient, and debugging can be performed directly by modifying the code. If the development environment is on the server, you can mount it to the local machine for development and modification by means of remote mount.

 

Scenario 3: If it is a test environment, it is recommended to use the git method, the code is not in the image, and the code corresponding to the test tag is pulled into the container through docker exec. Of course, you can also pull on the host, and then docker cp to the corresponding test container.

 

There is no such thing as the best, only the most suitable.

 

===========================

Docker deploys two scenarios:

1) Development environment
Since the code of the development environment is constantly changing, and many people collaborate through git, the code is placed outside, an image of the running environment is built, and then the code part is mapped into it with volume, which is convenient for adjustment at any time.

2) Production environment
Our production environment is relatively unique. Generally, we install finished products for customers instead of our own servers. On the one hand, in order to protect the code, on the other hand, to reduce unnecessary trouble, we build the code in the image, In this way, the image can be run directly on the client's side, which is just a download time, and no other operations are required.

 

On your own server, because it is basically an internal demo, it is treated as a development environment, see the first item.

Docker, since it can be a virtual environment, how can it be used appropriately? The purpose is to start quickly + rebuild quickly during development, and install it for customers as simple as possible.

===========================

 

1) The image is equivalent to a template. If the development code is placed in the image, the reusability of the image is reduced.

2) Whether the code is placed in the image to manage whether it will cause unnecessary burden on local storage and network transmission.

===========================

 

One of the practical scenarios:

1. In the development environment, because of the frequent changes of code, it is convenient to mount by volume.
2. After the code is submitted to the git repo, package and compile it through jenkins, generate the compiled code package into the docker image, tag the corresponding code, and upload it to the docker registry. Then enter the test environment for deployment and testing.
3. The docker image after paas ci can be deployed directly in the production environment.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326128099&siteId=291194637