ν™”. 8μ›” 12th, 2025

G: Are you tired of hearing, “But it works on my machine!”? πŸ€¦β€β™€οΈ Do you wish deploying applications was less of a headache and more of a breeze? If so, you’ve come to the right place! Docker is a game-changer in the world of software development and deployment, and by the end of this guide, you’ll understand why and even run your very first container!

This comprehensive guide will take you from the very basics of what Docker is, through installation on various operating systems, and finally, to running your first application container. Let’s dive in! πŸš€


1. What is Docker, and Why Should You Care? πŸ€”

Imagine you’re building a LEGO spaceship πŸš€. You’ve got all the pieces, the instructions, and a dedicated workspace. Now, imagine giving those exact pieces and instructions to a friend. Wouldn’t it be great if they could build the exact same spaceship, without missing any pieces or using different ones by mistake?

That’s essentially what Docker does for software!

Docker is a platform that uses OS-level virtualization to deliver software in packages called containers. Containers are isolated, lightweight, and portable environments that bundle an application and all its dependencies (libraries, frameworks, configurations, etc.) into a single, consistent unit.

Why is this revolutionary?

  • “It Works On My Machine” Solved! πŸ₯³: With Docker, your application runs in an isolated environment that’s identical across development, testing, and production. No more dependency hell!
  • Consistency: Every team member, every server, every environment runs the exact same code with the exact same setup.
  • Portability: A Docker container can run virtually anywhere Docker is installed – on your laptop, a cloud server, or even a Raspberry Pi. Just “build once, run anywhere.” 🌐
  • Isolation: Applications inside containers are isolated from each other and from the host system. This means conflicts between different applications are drastically reduced.
  • Efficiency: Containers share the host OS kernel, making them much lighter and faster to start than traditional virtual machines. πŸ’¨

2. Docker Core Concepts Explained Simply 🧠

Before we jump into installation, let’s understand two fundamental concepts that are key to Docker: Images and Containers.

2.1. Docker Images: The Blueprint πŸ“Έ

Think of a Docker Image as a blueprint, a template, or a read-only snapshot of an application and its environment. It contains:

  • The operating system (a minimal version, like Alpine Linux).
  • The application code (e.g., your Python script, a Node.js app).
  • All the necessary libraries and dependencies (e.g., Python interpreter, Node.js runtime).
  • Configuration files.

Images are built from a set of instructions defined in a Dockerfile. You can also download pre-built images from Docker Hub, a public registry similar to GitHub for Docker images.

Example:

  • An Nginx web server image (nginx).
  • A Python 3 image (python:3.9-slim).
  • A MySQL database image (mysql:8.0).

2.2. Docker Containers: The Running Instance πŸƒβ€β™‚οΈ

A Docker Container is a running instance of a Docker Image. Just like you can build many identical houses from one blueprint, you can run many identical containers from one image.

When you run an image, Docker creates a container, which is an isolated process that runs your application. You can start, stop, pause, restart, and delete containers. Each container has its own isolated file system, network interfaces, and process space.

Example:

  • You run the nginx image to start an Nginx web server container.
  • You run the python:3.9-slim image to execute a Python script inside a container.

3. Getting Started: Installing Docker Desktop πŸ’»πŸŽπŸ§

The easiest way to get started with Docker on your personal machine is by installing Docker Desktop. It includes Docker Engine, Docker CLI, Docker Compose, Kubernetes, and an easy-to-use user interface.

Before Installation: Ensure your system meets the minimum requirements. You’ll typically need a 64-bit processor and sufficient RAM (at least 4GB recommended).

3.1. Installation on Windows (Requires WSL 2) πŸ–₯️

For Windows, Docker Desktop leverages WSL 2 (Windows Subsystem for Linux 2) for better performance and compatibility.

  1. Enable WSL 2:

    • Open PowerShell as an administrator.
    • Run: wsl --install (This installs WSL and the Ubuntu distribution).
    • Restart your computer.
    • Set WSL 2 as the default version: wsl --set-default-version 2
    • If you already have WSL, ensure it’s updated to WSL 2: wsl -l -v to check version, then wsl --set-version <distro name> 2 for any v1 distros.
  2. Download Docker Desktop for Windows:

  3. Run the Installer:

    • Double-click the installer.
    • Follow the on-screen instructions. Ensure “Use WSL 2 instead of Hyper-V” is checked during installation.
    • After installation, Docker Desktop will start automatically. You might need to accept the terms and conditions and log in with your Docker ID (optional, but recommended for Docker Hub access).

3.2. Installation on macOS 🍎

  1. Download Docker Desktop for Mac:

  2. Run the Installer:

    • Double-click the downloaded .dmg file.
    • Drag the Docker icon to the Applications folder.
    • Open Docker from your Applications folder.
    • Accept the terms and conditions. You might need to grant Docker Desktop necessary permissions in System Settings/Preferences.

3.3. Installation on Linux 🐧

While Docker Desktop is available for Linux, many Linux users prefer installing the Docker Engine directly. The process varies by distribution. We’ll show a common way for Ubuntu, but always refer to the official Docker documentation for your specific Linux distribution for the most up-to-date and secure method.

For Ubuntu (Example):

  1. Uninstall old versions (if any):

    sudo apt-get remove docker docker-engine docker.io containerd runc
  2. Update your apt package index and install necessary packages:

    sudo apt-get update
    sudo apt-get install ca-certificates curl gnupg lsb-release
  3. Add Docker’s official GPG key:

    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  4. Set up the repository:

    echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  5. Install Docker Engine:

    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  6. Add your user to the docker group (to run Docker commands without sudo):

    sudo usermod -aG docker $USER

    You’ll need to log out and log back in for this change to take effect.

3.4. Verify Your Docker Installation βœ…

After installation, open your terminal (or PowerShell/CMD on Windows) and run these commands to ensure Docker is properly installed:

  1. Check Docker version:

    docker --version

    You should see something like: Docker version 24.0.5, build 463a0f7 (version numbers may vary).

  2. Run the hello-world container: This command will download a tiny “hello-world” image and run it in a container. If successful, it confirms Docker is working!

    docker run hello-world

    You should see output similar to this:

    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    719385800473: Pull complete
    Digest: sha256:f2266cbfc9d715d31f79fbc1134a68233e856846156a6520be39a67614ef6a72
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash

    Congratulations! Docker is up and running on your machine! πŸŽ‰


4. Your First Dive: Essential Docker Commands πŸŠβ€β™€οΈ

Now that Docker is installed, let’s learn some fundamental commands you’ll use constantly.

4.1. `docker pull

`: Downloading Images πŸ“₯ This command downloads a Docker image from Docker Hub (the default registry) to your local machine. * **Syntax:** `docker pull [:tag]` * `:tag` specifies a version (e.g., `nginx:1.21`). If omitted, `latest` is assumed. * **Example:** Download the Nginx web server image. “`bash docker pull nginx “` *Output:* “` Using default tag: latest latest: Pulling from library/nginx 9d5679586119: Pull complete a4866ad505a4: Pull complete … Status: Downloaded newer image for nginx:latest docker.io/library/nginx:latest “` #### 4.2. `docker images`: Listing Local Images πŸ–ΌοΈ This command lists all the Docker images currently stored on your local machine. * **Syntax:** `docker images` * **Example:** “`bash docker images “` *Output (example, your list may differ):* “` REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 130b91e9f14f 2 weeks ago 142MB hello-world latest f2266cbfc9d7 4 months ago 13.3kB “` #### 4.3. `docker run `: Running a Container ✨ This is the most frequently used command! It creates and starts a new container from a specified image. If the image isn’t available locally, Docker will automatically try to `pull` it. * **Syntax:** `docker run [OPTIONS] [:tag] [COMMAND] [ARG…]` * **Key Options for Beginners:** * `-d` or `–detach`: Runs the container in **detached mode** (in the background), so your terminal isn’t tied up. * `-p` or `–publish :`: Maps a port on your host machine to a port inside the container. Essential for accessing web applications! * `–name `: Gives your container a memorable name (otherwise, Docker generates a random one). * `-it`: Runs the container in **interactive mode** with a pseudo-TTY, useful for running shell commands inside the container (e.g., `docker run -it ubuntu bash`). * **Example 1: Running Nginx in detached mode and mapping ports** We’ll run Nginx, which serves web content on port 80 inside its container. We’ll map the host’s port 8080 to the container’s port 80. “`bash docker run -d -p 8080:80 –name my-nginx-app nginx “` *Output:* A long string (the container ID). `a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6` (your ID will be different) Now, open your web browser and go to `http://localhost:8080`. You should see the Nginx welcome page! πŸŽ‰ #### 4.4. `docker ps`: Listing Running Containers πŸ“Š This command lists all currently *running* containers. * **Syntax:** `docker ps` * **To see all containers (including stopped ones):** `docker ps -a` * **Example:** After running `my-nginx-app`: “`bash docker ps “` *Output (example):* “` CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1b2c3d4e5f6 nginx “/docker-entrypoint.…” 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp my-nginx-app “` Notice the `CONTAINER ID`, `IMAGE`, `PORTS`, and `NAMES` columns – these are very useful! #### 4.5. `docker stop `: Stopping a Container πŸ›‘ This command stops a running container gracefully. * **Syntax:** `docker stop ` * **Example:** “`bash docker stop my-nginx-app “` *Output:* `my-nginx-app` Now, if you check `docker ps`, `my-nginx-app` will no longer be listed. If you visit `http://localhost:8080`, it won’t be accessible. #### 4.6. `docker rm `: Removing a Container πŸ—‘οΈ This command deletes a stopped container. You cannot remove a running container unless you use the `-f` (force) flag. * **Syntax:** `docker rm ` * **Example:** “`bash docker rm my-nginx-app “` *Output:* `my-nginx-app` Now, `docker ps -a` will no longer show `my-nginx-app`. #### 4.7. `docker rmi `: Removing an Image 🧹 This command deletes an image from your local machine. You cannot remove an image if there are containers (even stopped ones) still referencing it. You must remove the containers first. * **Syntax:** `docker rmi [:tag]` * **Example:** “`bash docker rmi nginx “` *Output:* “` Untagged: nginx:latest Untagged: nginx@sha256:your_sha256_hash_here Deleted: sha256:image_id_here … “` — ### 5. Let’s Run Your First Real Application! (Nginx Web Server) 🌐 We already did a quick run, but let’s walk through it step-by-step to solidify your understanding. Nginx is a popular web server, and running it in a Docker container is incredibly simple. **Goal:** Run an Nginx web server in a Docker container and access it from your browser. **Steps:** 1. **Ensure no previous Nginx containers are running or existing:** Let’s clean up if you followed the previous examples. “`bash docker stop my-nginx-app # If it’s still running docker rm my-nginx-app # If it’s stopped but not removed “` *(You might get an error if they don’t exist, which is fine!)* 2. **Pull the Nginx image:** If you haven’t already, download the `nginx` image from Docker Hub. “`bash docker pull nginx “` *This downloads the latest Nginx image.* 3. **Run the Nginx container:** Now, let’s run it. * `-d`: Run in detached mode (background). * `-p 8080:80`: Map port 8080 on your host to port 80 inside the container (where Nginx listens). * `–name my-first-nginx`: Give our container a friendly name. * `nginx`: The image we want to run. “`bash docker run -d -p 8080:80 –name my-first-nginx nginx “` *You’ll see a long container ID printed.* 4. **Verify the container is running:** “`bash docker ps “` *You should see `my-first-nginx` listed with `Up` status and the port mapping `0.0.0.0:8080->80/tcp`.* 5. **Access Nginx in your browser:** Open your favorite web browser (Chrome, Firefox, Edge, Safari) and navigate to: “` http://localhost:8080 “` You should see the “Welcome to Nginx!” page. Success! πŸŽ‰ Your first application is running in Docker! 6. **Stop the container:** When you’re done, it’s good practice to stop containers you no longer need. “`bash docker stop my-first-nginx “` *This will stop the Nginx web server.* 7. **Remove the container (optional, but good for cleanup):** If you’re sure you don’t need this container instance anymore, remove it. “`bash docker rm my-first-nginx “` *The container is now gone, but the Nginx image remains on your machine for future use.* — ### 6. What’s Next? Your Docker Journey Continues! πŸ›£οΈ Congratulations! You’ve successfully installed Docker and run your first container. This is just the tip of the iceberg! Here are some next steps to deepen your Docker knowledge: * **Dockerfiles:** Learn how to write your own `Dockerfile` to create custom images for *your* applications. This is how you’ll containerize your own code! πŸ› οΈ * **Docker Compose:** For applications with multiple services (e.g., a web app, a database, and a caching layer), Docker Compose helps define and run them all with a single command. πŸ”— * **Volumes:** Understand how to make container data persistent. By default, container data is ephemeral (deleted when the container is removed). Volumes allow data to persist outside the container. πŸ’Ύ * **Networking:** Explore how containers communicate with each other and with the outside world. 🌐 * **Docker Hub:** Learn to push your own custom images to Docker Hub and share them with the world (or privately with your team). ☁️ * **Container Orchestration (Kubernetes/Swarm):** For managing large-scale deployments of many containers across multiple machines, tools like Kubernetes (K8s) and Docker Swarm become essential. — ### Conclusion πŸŽ‰ You’ve taken a huge step towards modern software development and deployment by learning the fundamentals of Docker. You now understand what containers are, why they’re so powerful, how to install Docker, and how to run your very first application. Docker is a fantastic tool that simplifies development, ensures consistency, and makes deployments much more reliable. Keep experimenting, keep building, and soon you’ll be harnessing the full power of containerization! If you have any questions or thoughts, feel free to share them! Happy Dockering! 🐳✨

λ‹΅κΈ€ 남기기

이메일 μ£Όμ†ŒλŠ” κ³΅κ°œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•„μˆ˜ ν•„λ“œλŠ” *둜 ν‘œμ‹œλ©λ‹ˆλ‹€