Skip to main content

๐Ÿ‘ฉโ€๐Ÿ’ป NestJS ็š„ dockerfile

ๅปบ็ซ‹ๆช”ๆกˆโ€‹

ๅœจๅฐˆๆกˆๅบ•ไธ‹ๅปบ็ซ‹ไธ€ๅ€‹ๆช”ๆกˆ dockerfile

# node image
FROM node:18-alpine

# ๅปบ็ซ‹app็›ฎ้Œ„
WORKDIR /usr/src/app

# ่ค‡่ฃฝไพ่ณดๆช”
COPY package*.json ./

COPY tsconfig*.json ./

# ่ค‡่ฃฝ็จ‹ๅผ็ขผ
COPY . .

# ไธ‹่ผ‰ไพ่ณด
RUN npm install

# ้ƒจๅฑฌๅฐˆๆกˆ
RUN npm run build

# ๅ•Ÿๅ‹•ๆœๅ‹™
CMD [ "node", "dist/main.js" ]

ๅœจๅฐˆๆกˆๅบ•ไธ‹ๅปบ็ซ‹ไธ€ๅ€‹ๆช”ๆกˆ .dockerignore๏ผŒไพ†้Žๆฟพ็”จไธๅˆฐ็š„ๆช”ๆกˆ

dockerfile
.dockerignore
node_modules
npm-debug.log
dist

ๅปบ็ซ‹ imageโ€‹

docker build -t nest-app .

ๅ•Ÿๅ‹• nest ๅฎนๅ™จโ€‹

docker run -p 80:3050 nest-app