화. 8월 12th, 2025

D: 🚀 Want to start containerizing your apps with Docker on Ubuntu? This step-by-step guide covers everything from installation to running your first container using the latest 2024 versions of Docker and Docker Compose. Let’s dive in!


🔧 Prerequisites

Before we begin, make sure you have:
✅ A machine running Ubuntu 22.04 LTS or 24.04 LTS (recommended)
sudo/root access (for installing packages)
Internet connection (to download Docker)


🛠 Step 1: Uninstall Old Docker Versions (If Any)

If you have an older Docker version, remove it first:

sudo apt-get remove docker docker-engine docker.io containerd runc

Step 2: Install Docker on Ubuntu

Option 1: Install Using the Official Docker Repository (Recommended)

This ensures you get the latest stable version.

1️⃣ Update your package list:

sudo apt-get update

2️⃣ Install dependencies:

sudo apt-get install -y ca-certificates curl gnupg lsb-release

3️⃣ Add Docker’s 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 Docker 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 -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin

6️⃣ Verify Docker is running:

sudo systemctl status docker

✅ Expected output: Active: active (running)

7️⃣ Test Docker with Hello-World:

sudo docker run hello-world

🎉 If you see Hello from Docker!, it’s working!


Option 2: Install via Convenience Script (Quick & Easy)

For a fast one-line install (not recommended for production):

curl -fsSL https://get.docker.com | sudo sh

🚀 Step 3: Post-Installation Setup

Run Docker Without Sudo (Optional but Recommended)

By default, Docker requires sudo. To avoid this:

1️⃣ Add your user to the docker group:

sudo usermod -aG docker $USER

2️⃣ Log out and back in (or restart) for changes to apply.

3️⃣ Test without sudo:

docker run hello-world

📦 Step 4: Install Docker Compose (v2 Latest Version)

Docker Compose is now integrated into Docker CLI (docker compose), but you can still install it separately:

1️⃣ Download the latest binary:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

2️⃣ Make it executable:

sudo chmod +x /usr/local/bin/docker-compose

3️⃣ Verify installation:

docker-compose --version

✅ Output: Docker Compose version v2.X.X


🏗 Step 5: Test Docker Compose with a Simple Project

Let’s create a basic docker-compose.yml file to run an Nginx web server:

1️⃣ Create a project folder:

mkdir ~/nginx-test && cd ~/nginx-test

2️⃣ Create docker-compose.yml:

version: "3.9"
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"

3️⃣ Run it!

docker-compose up -d

4️⃣ Check if Nginx is running:
Open http://localhost:8080 in your browser. You should see the Nginx welcome page! 🎉

5️⃣ Stop the container:

docker-compose down

🔥 Bonus Tips

Update Docker & Compose:

sudo apt-get update && sudo apt-get upgrade

Auto-start Docker on boot:

sudo systemctl enable docker

Clean up unused containers/images:

docker system prune -a

🎯 Conclusion

You’ve successfully installed Docker and Docker Compose on Ubuntu! 🚀 Now you can:

  • 🐳 Run containers effortlessly
  • 🛠 Deploy multi-container apps with docker-compose.yml
  • 🚀 Explore Docker Hub for pre-built images

👉 Next Steps? Try deploying a WordPress + MySQL stack or a Python Flask app with Docker Compose!

💬 Got stuck? Drop a comment below! Happy Dockering! 🐋

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다