Docker tutorial(2)

Sample application

Build the app’s Container image

Dockerfile은 컨테이미지를 만드는 구조의 스크립트이다. Dockerfile을 통해서 이미지를 만들어 본다.

  1. create file named Dockerfile in the same folder as the file package.json with the follwing contents.
1
2
3
4
5
6
7
# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python3 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
  1. Dockerfile이 있는 폴더로 이동한 후에 build 를 시작
1
$ docker build -t getting-started .

이 커멘드는 Dockerfile 을 사용해서 컨테이너 이미지를 만든다.

Start an app container

  1. docker run 을 통해 이미지를 실행시킨다.
1
$ docker run -dp 3000:3000 getting-started

다시한번 설명하자면 :

  • -d : background 실행
  • -p : 포트 매핑 host 3000 번 을 docker image 의 3000번 포트로
  1. localhost:3000 으로 접속하면 내용을 확인할 수 있다.

Docker Dashboard 에서 continaer 탭을 살펴보면 여러가지 컨테이너가 실행중인 것을 불수 있다. 다음에는 컨테이너를 관리 하는 방법을 살펴본다.