CONTAINER/docker
도커 파일만들기 nodejs
찌뮤
2021. 5. 30. 19:13
1. 프로젝트에 Dockerfile 만들기
vim Dockerfile
2. syntax parser directive 작성
# syntax=docker/dockerfile:1
- Must appear before any other comment
- Instructs the Docker builder what syntax to use when parsing the Dockerfile
- Allows older Docker versions with BuildKit enabled to upgrade the parser before starting the build
3. 베이스 이미지 설정하기
FROM node:12.18.1
- use the official Node.js image that already has all the tools and packages that we need to run a Node.js application
4. 환경변수 설정해주기
EMV NODE_NODE=production
어떤 역할을 하는지 잘 모르겠다. 알아보자
5. working directory 설정해주기
WORKDIR /app
- Instructs Docker to use this path as the default location for all subsequent commands
- Don't have to type full path, and use relateive apath based on the working directory.
6. package.json 과 package-lock.json 옮겨주기
COPY ["package.json", "package-lock.json*", "./"]
- npm install 하기 전에 패키지들의 의존성 정보를 담은 package.jon 을 옮겨주자
7. RUN 명령어로 컨테이너가 생성될때 사용할 명령어를 작성
RUN npm install --production
8. 사용할 소스파일 복사해주기
COPY . .
9. 컨테이너를 만들고 난뒤에 실행할 명령어
CMD [ "node", "dev", "start"]