# Docker deployment related # # Docker foundation - reference document [] (https://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html) based on micro Docker service deployment, It greatly avoids the disadvantages of environment configuration, slow startup, and many redundant steps. To get started, refer to the documentation above for a detailed look. ## Docker deployment preparation - 'DockerFile' To set the source of the image (that is, the environment in which the image is running, with 'NodeJS' in front), the command 'FROM' is used. 2. Put the required code into a unified file directory, remove the development code, and only keep a server and front-end Webpack packaged file. - Based on this content, the NPM package can be installed remotely and packaged remotely. - Because some current development projects need to use private NPM packages, so you need to set the source of NPM. - The '.npMRc 'file needs to be added to the project itself, which is already used for verification of downloading the NPM package. - Perform related operations on the remote end, such as operating files, copying and deleting files, and running sh commands. - FROM: sets the official version/operating base environment that the image inherits. - COPY: indicates the COPY command. - WORKDIR: indicates the working path of the mirror. -arg: 'DockerFile' -arg: 'DockerFile' -arg: 'DockerFile' -run: runs the sh command. Based on the preceding information, take a close look at the H5 DockerFile file. ARG proj_dir =./ CWP ARG PROJ_NAME= CWP ENV NODE_ENV preview ENV SERVER devel-c ENV SERVICE $PROJ_NAME # Set the time zone ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone COPY $LOCAL_PROJ_DIR/CWP RUN CD/CWP \ && npm install --registry=http://nexus.devops.xxxxxxxxx.com/repository/anpm/\ && npm run build \ && rm -rf client node_modules test webpack RUN cd /cwp/server \ && npm install --production --registry=http://nexus.devops.xxxxxxxxx.com/repository/anpm/ WORKDIR /cwp/server ``` 3. Preparing the Docker image package ------------ All the above are local preparations. After preparing the local preparations, deploy the Docker image on the server and run it as follows: 1. Based on the deployment server, log in to the server to be deployed. 2. Prepare the 'docker-comemess. yml' file. There are a few comments to describe this file. - docker-name Specifies the docker name. - docker-image Specifies the image source of the docker. - container_name Specifies the container name. Left-to-right -environment docker run parameter variable -command Docker run CMD command -network docker run network relationship, here is not to do the details, the service is generally 'common-network' 3. The following commands are commonly used on the server. - docker ps list of docker images running on the current service -grep modifier, Docker images - docker images - docker exec -it XXX /bin/sh Docker-compose up - tail Prints the output of a file, usually logs/info.log -cat displays the output of a file, take the H5 platform 'docker-compose. ` ` ` version: "2" services: # docker name XXX: image: registry.cn-hangzhou.aliyuncs.com/xxxxxx/xxxx restart the mirror version number: Always # container_name: XXX ports: - "7710:7710" environment: - NPM_CONFIG_LOGLEVEL=info - PORT=7710 - NODE_ENV=preview - REDIS_HOST=xxx-redis - REDIS_PORT=6379 - REDIS_DB=3 - REDIS_PASSWORD=admin123 - ES_PATH=http://xxxx.xxxx.xxxx.cn:8082/v2 command: ["npm", "run", "online"] mem_limit: 209715200 networks: default: external: name: test-network ```Copy the code