https://nosleepjavascript.com/docker-essentials-for-front-end-developers/

간단한 Nodejs / 프론트엔드 애플리케이션을 실행 시킬 때 무엇이 필요합니까?

도커 이미지란?

Dockerfile은 애플리케이션을 실행하는 데 필요한 단계의 순서 목록입니다. 각 줄은 성능상의 이유로 Docker가 캐시 하는 중간 이미지를 생성 하므로 순서가 중요합니다.

간단한 Nodejs 애플리케이션의 Dockerfile입니다.

# This is our base community provided image,
# with some minimal distribution of linux
# that comes with NodeJs v10 (and npm) already installed
FROM node:12

# Use this directory _inside_ your Docker container
# as the base directory of all the next actions
WORKDIR /usr/src/app

# Copy your app's code from the host (your computer) to the container.
# This assumes a typical setup in which the Dockerfile
# is in the root of your project
COPY package.json ./

# Install dependencies
RUN npm install

# Copy the rest of your App's source files
COPY . .

# Tell Docker that your app will be working in the port 8080
# so we should open it up to the outside
EXPOSE 8080

# Run your app.
# CMD signals Docker that this is the thing that we want to run,
# if this executable fails then the whole container will exit.
CMD [ "node", "server.js" ]

이미지는 단지 지침일 뿐이며 실행하면 컨테이너로 변환 됩니다.

컨테이너란?

최종 이미지를 구축한 후 실행 파일로 인스턴스화 할 수 있으며, 이 실행 파일은 컨터이너라고 하며 호스트 OS에 의해 다른 프로세스로 처리됩니다.

필수 명령어

Building

Dockerfile이 있는 현재 디렉토리에서 docker 이미지를 빌드 할 수 있습니다. 이렇게 만들어진 이미지를 나중에 인스턴스화 하는데 사용합니다.

docker build .
# OR
docker build ./Dockerfile