Docker is a platform for containerization — packaging an application and its dependencies into a portable, lightweight container that runs consistently across environments.
Docker Image
ubuntu:22.04
, node:20-alpine
.Docker Container
Dockerfile
Script to define how an image is built.
Example:
FROM node:20-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]
Docker Hub
Volumes
Networks
Command | Description |
---|---|
docker --version |
Check Docker version |
docker pull <image> |
Download an image from Docker Hub |
docker build -t <name>:<tag> . |
Build an image from Dockerfile |
docker images |
List local images |
docker ps |
List running containers |
docker ps -a |
List all containers |
docker run -d -p 8080:80 <image> |
Run container in background, map ports |
docker stop <container> |
Stop a running container |
docker rm <container> |
Remove container |
docker rmi <image> |
Remove image |
docker logs <container> |
View container logs |
docker exec -it <container> bash |
Open interactive shell inside container |