Installation environment

Install the docker

The startup script

The project structure

Deploy the script

# #! /usr/bin/env bash
CONTAINER_NAME=CONTAINER_NAM
IMAGE_NAME=CONTAINER_NAM

echo "Redeployment is under way${CONTAINER_NAME}"

# # Stop the running container
docker stop ${CONTAINER_NAME}

Delete old containers
docker rm -f ${CONTAINER_NAME}

# # Delete image to ensure that the latest image is downloaded
docker rmi ${IMAGE_NAME}

# # Rebuild
docker build -t ${IMAGE_NAME} .

Download the latest image and start
docker run -d -p 4900:80 --name ${CONTAINER_NAME} ${IMAGE_NAME}

echo "Container${CONTAINER_NAME}Redeployment successful."
Copy the code

dockerfile

# build from the latest version of NODE container
FROM node:alpine

ARG environment=' '

# Switch domestic Docker image source
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

COPY ./package.json /app/

WORKDIR /app

RUN rm -rf node_module

RUN npm install

COPY . /app

RUN npm run build$environment

Run the command to start the container
CMD $environment npm run prd

# indicates the exposed port of the container
EXPOSE 80

Copy the code