Dockerfile 읽기 및 컨테이너 실행

컨테이너화와 가상화 개념

Julia Ostheimer

Freelance AI Consultant

Docker 용어 복습

 

Dockerfile에서 Docker 컨테이너까지

컨테이너화와 가상화 개념

Docker 명령어 vs. Docker 커맨드

  • Docker 명령어: Docker 이미지 빌드 방법 명세

Dockerfile의 Docker 명령어

  • Docker 커맨드: CLI(명령줄 인터페이스)를 통한 명령

CLI의 Docker 커맨드

컨테이너화와 가상화 개념

Dockerfile 형식

 

Dockerfile - 주석

컨테이너화와 가상화 개념

Dockerfile 형식

 

Dockerfile - 명령어

컨테이너화와 가상화 개념

Dockerfile 형식

 

Dockerfile - Docker 명령어의 커맨드

컨테이너화와 가상화 개념

Dockerfile 형식

 

Dockerfile - Docker 명령어의 인수

컨테이너화와 가상화 개념

Dockerfile의 순차적 실행 순서

  • 순차적으로 실행
  • Dockerfile 시작 부분:
    • 메타데이터
    • 주석
    • 인수
    • FROM 명령어
컨테이너화와 가상화 개념

Docker 명령어 개요

  • 주요 Docker 명령어
    • FROM
    • COPY
    • RUN
    • ENTRYPOINT
컨테이너화와 가상화 개념

FROM 명령어

  • 기존 Docker 이미지 지정
  • 빌드할 기반 이미지 정의
    • "시작점"  

문법:

FROM <name_of_image>

예시:

# Define the image on which to build
FROM python:3.10
컨테이너화와 가상화 개념

COPY 명령어

  • 파일 또는 디렉터리 복사
    • 소스(<source>)에서 대상(<destination>)으로
    • 이후 Docker 명령어에 필요한 파일  

문법:

COPY <source> <destination>

예시:

# Copy files/folders to the main folder of the container
COPY . .
컨테이너화와 가상화 개념

RUN 명령어

  • 컨테이너 내에서 명령 실행
    • CLI에서 실행 가능한 모든 명령 사용 가능

 

문법:

RUN <command>

예시:

# Install the application's dependencies
RUN pip install -r requirements.txt
컨테이너화와 가상화 개념

ENTRYPOINT 명령어

  • 컨테이너의 기본 동작 정의
    • 시작 시 실행할 명령 지정
    • 컨테이너의 주요 목적  

문법:

ENTRYPOINT ["command", "argument"]

예시:

# Run the script when the container starts
ENTRYPOINT ["python", "hello_world.py"]
컨테이너화와 가상화 개념

Dockerfile에 명령어 조합하기

# Define the image on which to build
FROM python:3.10
컨테이너화와 가상화 개념

Dockerfile에 명령어 조합하기

# Define the image on which to build
FROM python:3.10

# Copy files/folders to the main folder of the container
COPY . .
컨테이너화와 가상화 개념

Dockerfile에 명령어 조합하기

# Define the image on which to build
FROM python:3.10

# Copy files/folders to the main folder of the container
COPY . .

# Install the application's dependencies
RUN pip install -r requirements.txt
컨테이너화와 가상화 개념

Dockerfile에 명령어 조합하기

# Define the image on which to build
FROM python:3.10

# Copy files/folders to the main folder of the container
COPY . .

# Install the application's dependencies
RUN pip install -r requirements.txt

# Run the script when the container starts
ENTRYPOINT ["python", "hello_world.py"]
컨테이너화와 가상화 개념

docker build 명령

  • Dockerfile로부터 Docker 이미지 빌드
    • Dockerfile은 빌드 컨텍스트(<context>) 내에 위치해야 함
    • CLI를 통해 Docker 클라이언트 명령으로 실행

 

문법:

docker build <context>
컨테이너화와 가상화 개념

docker run 명령

  • Docker 이미지로부터 컨테이너 생성 및 실행
    • Docker 이미지를 인수(<name_of_image>)로 지정
    • CLI를 통해 Docker 클라이언트 명령으로 실행

 

문법:

docker run <name_of_image>
컨테이너화와 가상화 개념

연습해 봅시다!

컨테이너화와 가상화 개념

Preparing Video For Download...