What is Docker?

Docker is an open source platform that enables automating the deployment of applications within software containers, providing an additional layer of abstraction and automation.

Key Concepts

Containers

A container is a standard unit of software that packages code and all its dependencies.

Images

A Docker image is a read-only template with instructions for creating a container.

Dockerfile

Text file that contains all the commands needed to build an image.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
FROM ubuntu:22.04

RUN apt-get update && apt-get install -y \
    python3 \
    python3-pip

WORKDIR /app

COPY requirements.txt .
RUN pip3 install -r requirements.txt

COPY . .

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

Basic Commands

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Build image
docker build -t my-app:latest .

# Run container
docker run -d -p 8080:80 my-app:latest

# List containers
docker ps

# View logs
docker logs <container-id>

# Stop container
docker stop <container-id>

Advantages

Portability: Works the same in any environment
Efficiency: Fewer resources than virtual machines
Isolation: Each container is independent
Scalability: Easy to scale horizontally

References