what is doceker layer ?
A Docker layer is a read-only part of a Docker image created during the image-building process.Each instruction in a Dockerfile such as FROM, RUN, COPY, or ADD creates a new layer.
Docker uses these layers to make images efficient, reusable, and faster to build.
suppose you have a docker file like this
FROM python:3.11
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python","manage.py","runserver"]
Docker executes one instruction at a time.Each instruction creates a read-only layer.
Layer 1:
FROM python:3.11
-------------------
Base OS + Python
Layer 2:
WORKDIR /app
-------------------
Creates working directory
Layer 3:
COPY requirements.txt .
-------------------
Adds requirements file
Layer 4:
RUN pip install
-------------------
Installs packages
Layer 5:
COPY . .
-------------------
Copies project code
Layer 6:
CMD
-------------------
Startup command
Start Docker build process
Read Dockerfile from top to bottom
Create base layer using FROM python:3.11
Create working directory using WORKDIR /app
Copy requirements.txt into container using COPY requirements.txt .
Install required packages using RUN pip install -r requirements.txt
Copy project files into container using COPY . .
Store startup command using CMD
Stack all layers together to form the final Docker image
Add a writable layer when a container runs from the image
Why Docker uses layers?
A.Faster build (Caching):