
Building Your Portfolio Experience
Loading Tariqul Islam's projects...
Loading Tariqul Islam's projects...
A complete step-by-step Docker guide covering installation, commands, networks, volumes, Dockerfile, and Docker Compose for beginners and professionals.
Docker is an open platform for developing, shipping, and running applications. It allows you to package applications and their dependencies into a container so they can run reliably in different computing environments.
Containers are lightweight, fast, and portable compared to traditional Virtual Machines.
Docker ensures your app works the same everywhere — from your laptop to production servers.
👉 Official Docs: Docker Overview
sudo apt update
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
docker --version
Install Docker Desktop 👉 Download Docker Desktop It comes with Docker Engine + Docker Compose + GUI.
Command | Description | Example |
---|---|---|
| Pull image from Docker Hub |
|
| List all images |
|
| Run container |
|
| Run in interactive mode |
|
| Stop running container |
|
| Start stopped container |
|
| Show running containers |
|
| Show all containers |
|
| Remove image |
|
| Remove container |
|
| Run in detached (background) mode |
|
| Run with custom name |
|
| Pull specific version |
|
Environment variables are used to configure containers (e.g., DB credentials).
Example: Running MySQL with root password
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:8
Docker images are built in layers.
Each instruction in a Dockerfile
creates a new read-only layer.
Containers are writable layers on top of images.
Container Layer (Writable)
│
├─ Layer 2
├─ Layer 1
└─ Base Layer (Linux)
Port binding connects a container’s internal port to a port on the host machine. This allows access to containerized apps from outside the container.
Syntax:
docker run -p <host_port>:<container_port> image
Example:
docker run -p 8080:80 nginx
8080
= host machine port
80
= container’s internal port
Access via: http://localhost:8080
Command | Description |
---|---|
| View container logs |
| Get shell access (bash) |
| Get shell access (sh) |
Docker | Virtual Machine |
---|---|
Lightweight, shares OS kernel | Heavy, separate OS for each VM |
Starts in seconds | Takes minutes to boot |
Uses MBs of memory | Uses GBs of memory |
Great for microservices | Great for full OS isolation |
Docker Desktop is a GUI tool for Windows/Mac that includes:
Docker Engine
Docker CLI
Docker Compose
A simple GUI to manage containers, images, and volumes
A Docker network is a communication channel that allows containers to talk to each other or the outside world.
bridge (default) → container-to-container on the same host
host → shares host networking (faster, less isolation)
null (none) → no networking
docker network ls # List networks
docker network create my_network # Create custom network
docker run --network=my_network ... # Attach container to network
Create a network:
docker network create mongo-network
Run MongoDB:
docker run -d --name mongodb \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=secret \
--network mongo-network \
mongo
Run Mongo Express:
docker run -d --name mongo-express \
-e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \
-e ME_CONFIG_MONGODB_ADMINPASSWORD=secret \
-p 8081:8081 \
--network mongo-network \
mongo-express
👉 Access UI: http://localhost:8081
Docker Compose is a tool for defining and running multi-container applications using a YAML file.
docker-compose.yaml
version: '3'
services:
mongodb:
image: mongo
container_name: mongodb
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=secret
networks:
- mongo-network
mongo-express:
image: mongo-express
container_name: mongo-express
ports:
- '8081:8081'
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=secret
networks:
- mongo-network
networks:
mongo-network:
driver: bridge
docker compose -f docker-compose.yaml up -d
docker compose -f docker-compose.yaml down
A Dockerfile is a script containing instructions to build a Docker image.
Dockerfile
FROM node:18 # Base image
WORKDIR /app # Set working dir
COPY package*.json ./ # Copy files
RUN npm install # Install deps
COPY . . # Copy source code
EXPOSE 3000 # Expose port
CMD ["npm", "start"] # Start app
docker build -t myapp:1.0 .
docker run -p 3000:3000 myapp:1.0
docker login
docker tag myapp:1.0 myusername/myapp:1.0
docker push myusername/myapp:1.0
Volumes are persistent storage mechanisms in Docker that allow data to survive container restarts or deletion.
Named Volume
docker run -v mydata:/data ubuntu
Anonymous Volume
docker run -v /data ubuntu
Bind Mount
docker run -v /host/path:/container/path ubuntu
docker volume ls
docker volume create myvol
docker volume rm myvol
docker volume prune # remove unused volumes
📘 Official Docs: Docker Docs
📺 YouTube Crash Course: Docker Tutorial
🐳 Docker Hub: hub.docker.com