Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Monday, August 24, 2026

Docker in simple english

1. What is Docker?

Docker is a platform that packages an application and everything it needs to run into a portable unit called a container.

In simple words:

Docker = Package your application + dependencies + configuration so it can run consistently anywhere.

For example, suppose you build a Python application.

Without Docker, your application might require:

  • Python 3.12
  • Flask
  • Specific Python libraries
  • Linux packages
  • Environment variables
  • Particular configuration

Your application may work perfectly on your computer but fail on another server because the environment is different.

With Docker, you package the application and its required environment into a Docker image, and then run that image as a container.

Simple example

Your Python Application

       

   Dockerfile

       

   Docker Image

       

   Docker Container

       

 Runs consistently



2. Docker vs Virtual Machine

 

This is one of the most important concepts.

 

 



Virtual Machine

 

Physical Server

     

  Hypervisor

     

   VM 1       VM 2

   OS         OS

   App        App

 

Each VM normally has its own complete operating system.

 

Docker

 

Physical Server

     

 Docker Engine

     

Container 1   Container 2

   App           App

 

Containers share the host's operating-system kernel, making them generally

lighter and faster to start than full VMs.



Easy comparison: Docker VS Virtual Machine

 

Important: Docker containers are not simply "small VMs."

 They use operating-system-level isolation.

3. Important Docker Terms

You should understand these before moving into advanced Docker.

 

a. Docker Engine

The software that runs and manages Docker containers.

 

Docker CLI

   

Docker Engine

   

Containers

 

b. Docker Image

A read-only template containing everything required to create a container.

 

Examples:

python:3.12

nginx:latest

ubuntu:24.04

mysql:8

 

Think:

Image = Blueprint

 

c. Docker Container

A running instance of an image.

 

Think:

Container = Running application created from the blueprint

 

For example:

nginx image

    

Container 1

Container 2

Container 3

 

One image can be used to create multiple containers.



d. Dockerfile

A text file containing instructions for creating a Docker image.

 

Example:-

FROM python:3.12

WORKDIR /app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY .

CMD ["python", "app.py"]


e. Docker Registry

A place where Docker images are stored.

The most popular public registry is Docker Hub.

 

For example:

 

Dockerfile

   

Docker Image

   

Docker Hub

   

Pull image on another server

   

Run container


4. Docker's Basic Workflow

You should memorize this workflow:

 

Write Application

      

Create Dockerfile

      

Build Image

      

Test Image

      

Push Image to Registry

      

Pull Image on Server

      

Run Container

 

For example:

 

Python App

   

Dockerfile

   

my-python-app:v1

   

Docker Hub

   

AWS EC2

   

Docker Container

 

This is where Docker becomes extremely useful in Cloud + DevOps.

 

5. Docker Commands

Once Docker is installed, start with these commands.

First Docker Commands — Quick Reference Table

N

Docker Command

What It Does

1

docker --version

Checks the installed Docker version.

2

docker info

Displays detailed information about the Docker installation and Docker Engine.

3

docker pull nginx

Downloads the Nginx Docker image from Docker Hub.

4

docker images

Lists all Docker images available on your system.

5

docker run nginx

Creates & starts a new container using the Nginx image.

6

docker run -d nginx

Runs an Nginx container in the background (detached mode).


 

7

docker ps

Shows currently running containers.

8

docker ps -a

Shows all containers, including stopped containers.

9

docker stop <container_id>, ex-docker stop abc123

Stops a running container.

10

docker rm <container_id>, ex- docker rm abc123

Removes a stopped container.

11

docker rmi <image_id>, ex-docker rmi abc123

Removes a Docker image from your system.



6. Docker Port Mapping

Suppose an application inside a container listens on:

Port 80

 

You can expose it through your host machine:

docker run -d -p 8080:80 nginx

 

Meaning:

 

Host Machine              Container

-----------               ---------

   8080  ───────────────→   80

 

You access:

http://localhost:8080

 

The request goes:

Browser

  

localhost:8080

  

Docker

  

Container:80

  

Nginx

 

The networking knowledge will make Docker networking much easier to understand.

 

7. Docker Volumes

Containers are generally treated as disposable. If important data exists only inside a container,

you can lose it when the container is removed.

Volumes provide persistent storage.

 

Docker Container

      

     Volume

      

Persistent Data

 

Example:

docker volume create mydata

 

Then:

docker run -d \

  -v mydata:/data \

  nginx

Bind mount = Host folder/file connected to container
Ex- Host C:\project → Container /app

Persistent storage = Storage that keeps data even after a container is stopped or deleted.
Docker volumes are commonly used for this.
Ex- Database data remains after container recreation.

Container filesystem = Container's own temporary storage
Ex- /app, /tmp, /var/log inside the container


8. Docker Networking

Important Docker networking concepts:

  • Bridge network
  • Host network
  • None network
  • Custom networks
  • Container-to-container communication
  • Port mapping
  • DNS between containers
  • Network isolation

 

                Docker Network

                                        

          ┌────────────────────┐

                                                                       

      Frontend                                              Backend

     Container                                             Container

                               

                               

                            Database

                           Container

 

 

Instead of connecting applications using random IP addresses, Docker's custom networks

allow containers to communicate using container/service names.

 

 

 

Wednesday, August 12, 2026

Dockerizing Web Applications — Easy Step-by-Step Guide

Docker allows us to package an application, its dependencies, and its configuration into a Docker Image, which can then be used to create and run Containers.

A simple Docker workflow is:

Application → Dockerfile → Docker Image → Docker Container → Browser

1. Dockerize an HTML Website Using Nginx

Nginx is a lightweight and popular web server used to serve HTML, CSS, JavaScript, and other static files.

Step 1 — Create Your HTML Website

Create a folder for your project and open it in Visual Studio Code.

Example:

my-html-website/
│
├── index.html
├── style.css
└── script.js

Create your index.html file.

Step 2 — Create a Dockerfile

Inside the project folder, create a file named exactly:

Dockerfile

Do not add .txt or another extension.

Add:

FROM nginx:alpine

COPY . /usr/share/nginx/html/

EXPOSE 80

What does this mean?


CommandMeaning
FROM nginx:alpineUses the lightweight Nginx image as the base image
COPY . /usr/share/nginx/html/    Copies your website files into Nginx's web directory
EXPOSE 80Documents that Nginx uses port 80

Step 3 — Build the Docker Image

Open CMD or PowerShell inside the project folder:

docker build -t webserver-image:v1 .

Meaning

  • docker build → Creates a Docker image

  • -t → Gives the image a name and tag

  • webserver-image → Image name

  • v1 → Version/tag

  • . → Use the current folder as the build context

Check the image:

docker images

Step 4 — Run the Container

docker run -d -p 8080:80 --name html-nginx webserver-image:v1

Meaning

  • -d → Runs the container in the background

  • -p 8080:80 → Maps your computer's port 8080 to Nginx's container port 80

  • --name html-nginx → Gives the container a name

Step 5 — Open the Website

Open your browser and visit:

http://localhost:8080

Your HTML website should now be running inside a Docker container.



2. Dockerize an HTML Website Using Apache2

Apache HTTP Server is another popular web server that can serve HTML websites.

Step 1 — Create Your HTML Website

Example:

apache-html-site/
│
├── index.html
├── style.css
└── script.js

Step 2 — Create the Dockerfile

Create:

Dockerfile

Add:

FROM httpd:2.4

COPY . /usr/local/apache2/htdocs/

EXPOSE 80

Explanation

CommandMeaning
FROM httpd:2.4Uses Apache HTTP Server image
COPY . /usr/local/apache2/htdocs/   Copies website files into Apache's web directory
EXPOSE 80Documents Apache's HTTP port


Step 3 — Build the Image

docker build -t apache-html-site:v1 .

Check it:

docker images

Step 4 — Run the Container

docker run -d -p 8084:80 --name apache-html apache-html-site:v1


Step 5 — Open in Browser

http://localhost:8084

Your HTML website is now running through Apache inside Docker.



3. Dockerize a React Website

For a React application, we normally use a multi-stage Docker build.

The process is:

React Source Code
       ↓
Node.js
       ↓
npm install
       ↓
npm run build
       ↓
Production Build
       ↓
Nginx
       ↓
Docker Container

The first stage uses Node.js to build the React application.

The second stage uses Nginx to serve the generated static files.

Step 1 — Create Your React Application

Your project should normally look similar to:

react-app/
│
├── public/
├── src/
├── package.json
├── package-lock.json
└── Dockerfile

Important: Create the Dockerfile in the React project's root folder, not normally inside the src folder.

Step 2 — Create the Dockerfile

# Stage 1: Build the React application
FROM node:alpine AS build

# Set working directory
WORKDIR /app

# Copy package files first
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy application source code
COPY . .

# Create production build
RUN npm run build


# Stage 2: Serve the application using Nginx
FROM nginx:alpine

# Copy React production files to Nginx
COPY --from=build /app/build /usr/share/nginx/html

# Nginx uses port 80
EXPOSE 80

# Keep Nginx running in the foreground
CMD ["nginx", "-g", "daemon off;"]

What is happening?

Stage 1 — Node.js

Node.js is used to:

  1. Install React dependencies.

  2. Copy the source code.

  3. Run npm run build.

  4. Generate optimized production files.

Stage 2 — Nginx

Nginx is used to:

  1. Take the production build.

  2. Serve the static files.

  3. Provide the website through HTTP.

This approach produces a much smaller production image than keeping Node.js and all development dependencies in the final image.

Step 3 — Create .dockerignore

Create a file named:

.dockerignore

Example:

node_modules
npm-debug.log
build
.git
.gitignore
*.md
Dockerfile
.dockerignore

This prevents unnecessary files from being sent to Docker during the build.

Step 4 — Build the React Image

Open CMD or PowerShell in the React project folder:

docker build -t reactapp:v1.1 .

Step 5 — Check the Image

docker images

You should see your React image in the list.

Step 6 — Run the Container

docker run -d --name reactappContainer -p 805:80 reactapp:v1.1

Step 7 — Open React Application

Open:

http://localhost:805

Your React application should now be running inside Docker.

Important Note

Some modern React projects use Vite instead of Create React App.

For Vite, the production folder is normally:

dist

instead of:

build

In that case, the Nginx line should be:

COPY --from=build /app/dist /usr/share/nginx/html

4. Dockerize a Node.js Web Application

Node.js applications usually run their own application server.

For example:

Browser
   ↓
Port 3000
   ↓
Node.js Application

Step 1 — Create Your Node.js Application

Example:

node-app/
│
├── server.js
├── package.json
├── package-lock.json
└── Dockerfile

Step 2 — Create the Dockerfile

FROM node:24-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["node", "server.js"]

Explanation

CommandPurpose
FROM node:24-alpine Uses Node.js Alpine image
WORKDIR /app Creates/uses /app inside the container
COPY package*.json ./ Copies package files
RUN npm install   Installs Node.js dependencies
COPY . . Copies application code
EXPOSE 3000 Documents application port
CMD ["node", "server.js"] Starts the Node.js application

Step 3 — Build the Image

docker build -t node-app:v1 .

Step 4 — Run the Container

docker run -d --name node-container -p 3000:3000 node-app:v1

Step 5 — Open the Application

Open:

http://localhost:3000

Important

Your Node.js application must listen on:

0.0.0.0

inside the container, rather than only localhost, otherwise the application may not be accessible from your host machine.



5. Push a Docker Image to Docker Hub

Docker Hub can be used to store and share Docker images.

The basic process is:

Build
  ↓
Tag
  ↓
Login
  ↓
Push
  ↓
Docker Hub

Step 1 — Build the Image

docker build -t node-app:v1 .

Step 2 — Login to Docker Hub

docker login

Enter your Docker Hub username and password/token when prompted.

Step 3 — Tag the Image

Replace yourdockerusername with your actual Docker Hub username:

docker tag node-app:v1 yourdockerusername/node-app:v1

For example:

docker tag node-app:v1 parveenbarak/node-app:v1

Step 4 — Check Images

docker images

Step 5 — Push the Image

docker push yourdockerusername/node-app:v1

Example:

docker push parveenbarak/node-app:v1

The image is now available in your Docker Hub repository.

6. Pull an Image from Docker Hub

If the image is available on Docker Hub, another computer can download it.

Step 1 — Login

docker login

Step 2 — Pull the Image

docker pull yourdockerusername/node-app:v1

Example:

docker pull parveenbarak/node-app:v1

Step 3 — Run the Downloaded Image

docker run -d -p 3000:3000 yourdockerusername/node-app:v1

Then open:

http://localhost:3000

7. Remove Docker Images

To remove a local image:

docker rmi node-app:v1

To remove a Docker Hub-tagged image:

docker rmi yourdockerusername/node-app:v1

Check images:

docker images

8. Dockerize a Python Application



Python applications can also be packaged and run inside Docker.

For this example, we will create a simple Python HTTP server.

Step 1 — Create app.py

Create:

app.py

Add:

from http.server import SimpleHTTPRequestHandler, HTTPServer

PORT = 5000

class MyHandler(SimpleHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        self.wfile.write(b"Hello World from Docker in Browser!")

server = HTTPServer(("0.0.0.0", PORT), MyHandler)

print(f"Server running on port {PORT}")

server.serve_forever()

Step 2 — Create the Dockerfile

Project structure:

python-app/
│
├── app.py
└── Dockerfile

Dockerfile:

FROM python:3.10-slim

WORKDIR /app

COPY app.py .

EXPOSE 5000

CMD ["python", "app.py"]

Explanation

CommandMeaning
FROM python:3.10-slim   Uses a lightweight Python image
WORKDIR /appSets /app as the working directory
COPY app.py .Copies the Python application
EXPOSE 5000Documents port 5000
CMDStarts the Python application

Step 3 — Build the Image

docker build -t python-web:v1 .

Step 4 — Run the Container

docker run -d --name python-web -p 5000:5000 python-web:v1

Step 5 — Open in Browser

http://localhost:5000

You should see:

Hello World from Docker in Browser!

9. Complete Docker Image Workflow

The most important Docker commands to remember are:

CommandPurpose
docker buildBuild an image from a Dockerfile
docker images List local Docker images
docker runCreate and start a container
docker psShow running containers
docker ps -aShow all containers
docker stopStop a container
docker startStart a stopped container
docker rmRemove a container
docker rmiRemove an image
docker loginLogin to Docker Hub
docker tagGive an image another name/tag
docker pushUpload an image to Docker Hub
docker pullDownload an image from Docker Hub

10. Easy Real-Life Example

Think about Docker like a food delivery system:

Dockerfile = Recipe

It tells Docker how to prepare your application.

Docker Image = Ready-to-use packaged food

It contains everything required to run the application.

Docker Container = The food being served

The image is used to create a running container.

docker build = Cooking the food

docker build -t myapp:v1 .

docker push = Putting the food in an online store

docker push username/myapp:v1

docker pull = Ordering the ready food

docker pull username/myapp:v1

docker run = Serving the food

docker run -d -p 8080:80 myapp:v1

11. Overall Docker Workflow

For most web applications, remember this simple workflow:

1. Create Application
        ↓
2. Create Dockerfile
        ↓
3. Write Docker Instructions
        ↓
4. docker build
        ↓
5. Docker Image Created
        ↓
6. docker run
        ↓
7. Docker Container Started
        ↓
8. Open localhost in Browser
        ↓
9. docker tag
        ↓
10. docker push
        ↓
11. Docker Hub
        ↓
12. docker pull
        ↓
13. Run Application Anywhere

Quick Examples

HTML + Nginx

docker build -t html-site:v1 .
docker run -d -p 8080:80 html-site:v1

Browser:

http://localhost:8080

HTML + Apache

docker build -t apache-site:v1 .
docker run -d -p 8084:80 apache-site:v1

Browser:

http://localhost:8084

React + Nginx

docker build -t reactapp:v1 .
docker run -d -p 805:80 reactapp:v1

Browser:

http://localhost:805

Node.js

docker build -t node-app:v1 .
docker run -d -p 3000:3000 node-app:v1

Browser:

http://localhost:3000

Python

docker build -t python-web:v1 .
docker run -d -p 5000:5000 python-web:v1

Browser:

http://localhost:5000

Key Point to Remember

Dockerfile → Image → Container

  • Dockerfile: Instructions for building your application image.

  • Image: Packaged, read-only template containing the application and required dependencies.

  • Container: A running instance of the image.

  • Port Mapping: Connects a port on your computer to a port inside the container.

  • Docker Hub: A registry where Docker images can be stored and shared.

Linux vs Windows System Administration Roadmap | Common Skills Guide

 Common Roadmap for Linux & Windows System Administrators Linux System Administration and Windows SystemAdministration have many commo...