0Pricing
Docker & Kubernetes for Developers · 강의

이미지용 Dockerfile 작성

애플리케이션 환경과 종속 항목을 이미지로 패키징하는 방법을 정의하는 Dockerfile 작성법을 학습합니다.

이미지용 Dockerfile 작성은(는) CoddyKit의 무료 Docker & Kubernetes for Developers 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Docker & Kubernetes for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What are Dockerfiles?

Welcome to creating your own Docker images! The heart of this process is the Dockerfile.

A Dockerfile is a simple text file that contains a series of instructions. These instructions tell Docker exactly how to build a Docker image, step by step.

Why Use a Dockerfile?

Dockerfiles automate the image creation process. Instead of manually setting up an environment, you define it once in a Dockerfile.

  • Reproducibility: Ensures everyone builds the exact same image.
  • Version Control: Dockerfiles can be stored in Git, just like your code.
  • Efficiency: Speeds up development and deployment workflows.

Starting Point: The FROM Instruction

Every Dockerfile must start with the FROM instruction. It specifies the base image your image will be built upon.

Think of it as choosing the operating system and initial software for your container. For example, ubuntu:22.04 or node:18-alpine.

FROM node:18-alpine

Running Commands: The RUN Instruction

The RUN instruction executes commands during the image build process. This is where you install software, update packages, or create directories.

Each RUN instruction creates a new layer in your image.

FROM node:18-alpine
RUN apk add --no-cache git

Setting the Workspace: WORKDIR

The WORKDIR instruction sets the working directory for any subsequent RUN, CMD, ENTRYPOINT, COPY, or ADD instructions.

It's good practice to set a specific directory for your application files.

FROM node:18-alpine
WORKDIR /app

Adding Files: The COPY Instruction

The COPY instruction copies files or directories from your local machine (the build context) into the Docker image filesystem.

The first argument is the source path on your machine, the second is the destination path inside the image.

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./

Installing Dependencies

After copying your project's dependency files (like package.json for Node.js), you'll typically use RUN again to install them.

This step ensures your application has all it needs to run.

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .

Exposing Ports: The EXPOSE Instruction

The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.

It's documentation for users, not an actual publishing of the port. You'll publish ports when you run the container.

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000

Default Command: The CMD Instruction

The CMD instruction provides a default command to be executed when a container starts from the image.

Unlike RUN, CMD runs when the container is launched, not during the build. You can override it when running the container.

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

Complete Dockerfile Example

Here's a full example of a simple Dockerfile for a Node.js web application. Each line contributes to building the final image.

# Use an official Node.js runtime as a parent image
FROM node:18-alpine

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json to install dependencies
COPY package*.json ./

# Install application dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Make port 3000 available to the world outside this container
EXPOSE 3000

# Define the command to run your app
CMD ["npm", "start"]

Dockerfile Instruction Check

Which Dockerfile instruction is used to execute commands during the image build process, such as installing packages or creating directories?

Recap: Crafting Dockerfiles

You've learned the essential instructions for crafting Dockerfiles:

  • FROM: Sets the base image.
  • RUN: Executes commands during build.
  • WORKDIR: Sets the working directory.
  • COPY: Copies files into the image.
  • EXPOSE: Declares listening ports.
  • CMD: Sets the default command to run on container start.

Mastering these allows you to define your application's environment precisely!

자주 묻는 질문

“이미지용 Dockerfile 작성” 강의는 무료인가요?

네 — “이미지용 Dockerfile 작성” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Docker & Kubernetes for Developers 강의 전체를 잠금 해제할 수 있습니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

“이미지용 Dockerfile 작성”에서 뭘 배우나요?

애플리케이션 환경과 종속 항목을 이미지로 패키징하는 방법을 정의하는 Dockerfile 작성법을 학습합니다. 브라우저에서 직접 실행하는 실습 코드로 Docker & Kubernetes for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Docker & Kubernetes for Developers을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Docker & Kubernetes for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“이미지용 Dockerfile 작성” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Docker & Kubernetes for Developers 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Docker & Kubernetes for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 이미지용 Dockerfile 작성
  2. 사용자 지정 Docker 이미지 빌드
  3. Compose를 활용한 다중 컨테이너 앱
  4. Docker 볼륨으로 데이터 영속화하기
← Docker & Kubernetes for Developers(으)로 돌아가기