0Pricing
Docker & Kubernetes for Developers · Ders

İmajlar için Dockerfile oluşturma

Uygulama ortamınızın ve bağımlılıklarının bir imajda nasıl paketleneceğini tanımlayan Dockerfile dosyaları yazmayı öğrenin.

İmajlar için Dockerfile oluşturma, CoddyKit'te ücretsiz bir Docker & Kubernetes for Developers dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Docker & Kubernetes for Developers öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Docker & Kubernetes for Developers kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

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!

Sıkça Sorulan Sorular

“İmajlar için Dockerfile oluşturma” dersi ücretsiz mi?

Evet — “İmajlar için Dockerfile oluşturma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Docker & Kubernetes for Developers kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Docker & Kubernetes for Developers kursu toplamda 4 dersten oluşur.

“İmajlar için Dockerfile oluşturma” dersinde ne öğreneceğim?

Uygulama ortamınızın ve bağımlılıklarının bir imajda nasıl paketleneceğini tanımlayan Dockerfile dosyaları yazmayı öğrenin. Docker & Kubernetes for Developers ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Docker & Kubernetes for Developers öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Docker & Kubernetes for Developers, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“İmajlar için Dockerfile oluşturma” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Docker & Kubernetes for Developers dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Docker & Kubernetes for Developers dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. İmajlar için Dockerfile oluşturma
  2. Özel Docker imajları oluşturma
  3. Compose ile çok konteynerli uygulamalar
  4. Docker Birimleriyle Verileri Kalıcılaştırma
← Docker & Kubernetes for Developers Sayfasına Dön