background

There are always various problems in the deployment process. For example, when the function is started, it cannot run normally in the Docker container. For such problems, it is not easy to debug or locate. Today, I recorded a problem I encountered: an image processing library. When installing it, I needed to download some binary files. It was very slow to install in Jenkins, and it was almost impossible to install

The solution

So I asked the architect of the department, he told me that if the installation is really not up, you can use the local package a basic image to deploy.

In the basic image mode, the package.json of the project is separated into a project under the environment of good running of the local machine, and the basic image operation from Node and NPM install operation are carried out in the project. After the installation of dependencies, docker build is carried out. Push the local image onto the container cloud, which is a base image.

Basic Image Configuration

FROM node:latest
LABEL liyonglong "[email protected]"

COPY . /usr/src/webapp
WORKDIR /usr/src/webapp

CMD npm install 
Copy the code

Then the Docker build is pushed to the container cloud

Then the mirror of the business item from is the base mirror that was just pushed up

Service item mirroring configuration

The FROM nodeservice - basic: node - 12.15.0 - v1 LABEL liyonglong"[email protected]"

COPY . /usr/src/webapp
WORKDIR /usr/src/webapp

EXPOSE 8082

CMD node .
Copy the code

This solves the dependency problem

In fact, it not only solves the dependency problem, but also avoids 80% of the problem that docker can’t get up in this way. Basically, it can ensure that your container can be started, and most of the problems generated after starting are code and host or configuration problems

Advantages and disadvantages analysis

  1. Fixed most containers not being started
  2. As much as possible, the development environment is consistent with the online environment

disadvantages

  1. Added deployment steps: if a new tripartite package is installed, or changes are madepackage.jsonThe tripartite package version needs to update the base image
  2. If it is through the machinedockerIt is easy to cause security problems: for example, I must log in the container cloud on the local computer, so that I can pull and push the image, but it may happen, of course, it can be avoided

In general, this way is a very good put, compared with the mirror in the production of up, dependent on inconsistent, inconsistent environment can be basically solved!