53 lines
1.1 KiB
Docker
53 lines
1.1 KiB
Docker
# sudo docker build -t api .
|
|
|
|
# 後續查看容器
|
|
# docker ps
|
|
# sudo docker exec -it [Container ID] /bin/bash
|
|
|
|
# 選擇node
|
|
FROM node:20.9.0
|
|
|
|
# 安装系统依赖
|
|
RUN apt-get update && apt-get install -y \
|
|
libcairo2-dev \
|
|
libjpeg-dev \
|
|
libpango1.0-dev \
|
|
libgif-dev \
|
|
build-essential
|
|
|
|
# 指定NODE_ENV為production
|
|
ENV NODE_ENV=production
|
|
|
|
# 指定預設/工作資料夾
|
|
WORKDIR /app
|
|
|
|
VOLUME ["/certificate"]
|
|
|
|
# 复制 package.json
|
|
COPY package.json ./
|
|
|
|
# 安裝dependencies
|
|
# If you are building your code for production
|
|
# RUN npm ci --only=production
|
|
RUN npm install
|
|
|
|
# copy其餘目錄及檔案
|
|
COPY . .
|
|
|
|
# 指定啟動container後執行命令
|
|
CMD [ "npm", "start" ]
|
|
|
|
|
|
|
|
# 将 Docker 镜像保存为文件
|
|
# sudo docker save -o api.tar api
|
|
|
|
# 使用 scp 传输文件到目标机器
|
|
# scp -P 20022 api.tar jianmiau@192.168.0.77:~/Nas/docker
|
|
|
|
# 在目标机器上加载镜像
|
|
# sudo docker load -i /path/to/destination/api.tar
|
|
|
|
|
|
|
|
# sudo docker run -v /volume1/homes/JianMiau/www/certificate:/certificate -e TZ=Asia/Taipei --name=api --restart always --net=host api |