Sobes.tech
Junior — Middle

Explain what a Docker image is and how it is used for containerizing applications.

sobes.tech AI

Answer from AI

A Docker image is a template that contains all the necessary components to run an application: code, libraries, dependencies, and environment settings. It serves as the basis for creating containers — isolated environments that run identically on any machine with Docker.

Using images ensures that the application will work the same across different environments (development, testing, production), simplifies deployment, and scaling. Images are created based on a Dockerfile — a text file with build instructions.

Example Dockerfile for a simple Node.js application:

FROM node:14
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]

This image can be built with the command docker build -t myapp ., and then run as a container with docker run myapp.