What is a Docker image?
· Category: Docker
Short answer
A Docker image is a read-only template containing a set of instructions for creating a Docker container. It includes the application code, runtime, libraries, environment variables, and configuration files needed to run the application.
How it works
Images are built in layers using a union file system. Each instruction in a Dockerfile creates a new layer that is cached and reused when possible. This layered approach makes images efficient to store and transfer, since only changed layers need to be rebuilt or pushed. Images are stored in registries like Docker Hub or private registries.
Example
Create a custom image for a Node.js application:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
USER node
CMD ["node", "server.js"]
List local images:
docker images
Why it matters
Docker images provide a standardized, immutable artifact that can be versioned, shared, and deployed anywhere Docker runs. This immutability ensures that what you test is exactly what you deploy, reducing environment-related bugs and simplifying rollback procedures.