CodeDigit
Back to Home

How to Set Up Docker on Ubuntu 20.04, 22.04, and 24.04 LTS – From Installation to Multi-Container Deployment

Admin User

Admin User

June 01, 2025 11:49 AM · 5 min read

Developer
How to Set Up Docker on Ubuntu 20.04, 22.04, and 24.04 LTS – From Installation to Multi-Container Deployment

🐳 Introduction to Docker

Docker simplifies app deployment by packaging code and dependencies into portable containers. It’s widely used for both development and production environments due to its consistency and efficiency.


🔧 Installing Docker on Ubuntu 20.04, 22.04, and 24.04 LTS

Step 1: Uninstall Old Versions (if any)

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

Step 2: Update Packages & Install Dependencies

bash
sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common

Step 3: Add Docker’s GPG Key

bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Step 4: Add Docker’s Repository

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

Step 5: Install Docker Engine

bash
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io

Step 6: Verify Docker Installation

bash
sudo docker --version sudo docker run hello-world

📦 Getting and Creating Docker Images

Use Prebuilt Images (from Docker Hub)

bash
docker pull nginx docker pull node

Browse: https://hub.docker.com

Create Your Own Docker Image

Create a Dockerfile:

Dockerfile
# For Node.js app FROM node:18 WORKDIR /app COPY . . RUN npm install CMD ["npm", "start"] EXPOSE 3000

Then build it:

bash
docker build -t my-node-app .

🧰 Useful Docker Commands

CommandDescriptiondocker psShow running containersdocker imagesList local imagesdocker exec -it <id> bashEnter running containerdocker stop <id>Stop a containerdocker rm <id>Remove a containerdocker rmi <id>Remove an image


🕸️ Containerizing Multiple Servers (Frontend + Backend)

Folder structure:

project-root/ ├── backend/ │ └── Dockerfile ├── frontend/ │ └── Dockerfile └── docker-compose.yml

docker-compose.yml:

yaml
version: '3' services: frontend: build: ./frontend ports: - "3000:3000" depends_on: - backend backend: build: ./backend ports: - "5000:5000" environment: - NODE_ENV=production

Run everything:

bash
docker-compose up --build

Internal Networking

  • Docker Compose automatically creates a default network.

  • Services can communicate using their service name (frontend, backend) as hostname.

Example: Your frontend can make an API call to http://backend:5000/api.


✅ Wrapping Up

You now know how to:

  • Install Docker on Ubuntu LTS

  • Use Docker images and containers

  • Build custom images

  • Deploy full-stack apps using Docker Compose

  • Utilize Docker networking for internal communication

Docker is an essential tool for modern DevOps and deployment workflows. Master it once, and you’ll level up your development and deployment pipeline.


Tags

UbuntuDockernginx

Comments (0)

Leave a comment

Related Posts