-
Notifications
You must be signed in to change notification settings - Fork 1
Docker
Adarsh Verma edited this page Aug 23, 2025
·
1 revision
- Docker is a containerization platform.
- A container is like a lightweight virtual machine.
- Instead of installing everything on your system, you package your app and all its dependencies inside a container so it runs the same everywhere.
-
Image → Blueprint of your app (like a template).
Example:node:18-alpineis a Node.js image. -
Container → Running instance of an image.
Example: When you run docker runnode:18-alpine, you create a container from that image. -
Dockerfile → A text file with instructions to build your own image.
-
Docker Hub → A public repo where images are stored (like GitHub for Docker).
# List all running containers
docker ps
# List all containers (including stopped)
docker ps -a
# List images
docker images
# Run a container
docker run -it ubuntu bash
# Stop a container
docker stop <container_id>
# Remove a container
docker rm <container_id>
# Remove an image
docker rmi <image_id>FROM node:18-alpine # Layer 1
WORKDIR /app # Layer 2
COPY package*.json ./ # Layer 3
RUN npm install # Layer 4
COPY . . # Layer 5# Build image
docker build -t my-node-app .
# Run container
docker run -p 3000:3000 my-node-appdocker run -d -p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=secret \
-v mysql-data:/var/lib/mysql \
mysql:latest
By default, containers on the same bridge network can communicate using container names.
# Create network
docker network create mynet
# Run MongoDB in network
docker run -d --name mongo --network mynet mongo
# Run Node.js in same network
docker run -it --network mynet node bash
# Inside node container -> "ping mongo" workslets you define multiple containers (services) in one docker-compose.yml file & Run docker-compose up -d.
version: '3.8'
services:
server:
build: .
ports:
- '3000:3000'
depends_on:
- mongo
volumes:
- .:/app
mongo:
image: mongo
ports:
- '27017:27017'
volumes:
- mongo-data:/data/db
volumes:
mongo-data: