https://github.com/swayamgupta12345/docker
A complete Docker command reference and revision guide with examples, flags, and workflows. Perfect for beginners to quickly revise everything from building images to pushing on Docker Hub.
https://github.com/swayamgupta12345/docker
docker docker-compose docker-image dockerfile
Last synced: about 2 months ago
JSON representation
A complete Docker command reference and revision guide with examples, flags, and workflows. Perfect for beginners to quickly revise everything from building images to pushing on Docker Hub.
- Host: GitHub
- URL: https://github.com/swayamgupta12345/docker
- Owner: SwayamGupta12345
- Created: 2025-04-05T14:32:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-05T14:38:49.000Z (about 1 year ago)
- Last Synced: 2025-04-05T15:29:04.687Z (about 1 year ago)
- Topics: docker, docker-compose, docker-image, dockerfile
- Language: JavaScript
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ณ Docker Revision Guide
This repository contains a comprehensive Markdown guide for Docker, designed for quick revision and long-term reference. It includes:
- ๐ง Common Docker commands
- ๐ Building & running images/containers
- ๐ฆ Dockerfile examples
- ๐ ๏ธ Docker Hub workflow
- ๐งน Cleanup and image management tips
- ๐ท๏ธ All commonly used flags explained
Whether you're just getting started or brushing up before a deployment, this guide keeps you covered.
# ๐ณ Docker Full Revision Guide
A comprehensive revision Markdown file to help you recall and revise all key Docker concepts and commands.
---
## ๐ฆ 1. Installation & Setup
### ๐น Install Docker
- [Docker Desktop (Windows/Mac)](https://www.docker.com/products/docker-desktop)
- Linux: Use your package manager (e.g., `apt`, `dnf`)
### ๐น Check Docker Version
```bash
docker --version
```
### ๐น Check Docker Status
```bash
docker info
```
---
## ๐ณ 2. Docker Basics
### ๐น Pull an Image
```bash
docker pull :
```
- Example: `docker pull ubuntu:20.04`
### ๐น Run a Container
```bash
docker run [OPTIONS] [COMMAND]
```
**Common Flags:**
- `-d` : Run in detached mode (in background)
- `-p` : Port mapping (e.g., `-p 8080:80`)
- `--name` : Assign a name
- `-it` : Interactive + TTY (for shell access)
Example:
```bash
docker run -d -p 3000:3000 --name myapp node:18
```
### ๐น List Running Containers
```bash
docker ps
```
### ๐น List All Containers (including stopped)
```bash
docker ps -a
```
### ๐น Stop a Container
```bash
docker stop
```
### ๐น Start a Stopped Container
```bash
docker start
```
### ๐น Remove a Container
```bash
docker rm
```
---
## ๐ 3. Docker Images
### ๐น List Images
```bash
docker images
```
### ๐น Remove an Image
```bash
docker rmi
```
Use `-f` to force:
```bash
docker rmi -f
```
### ๐น Build an Image from Dockerfile
```bash
docker build -t :tag .
```
Example:
```bash
docker build -t swayamgupta12345/learn:latest .
```
### ๐น Tag an Image
```bash
docker tag /:
```
### ๐น Push to Docker Hub
```bash
docker push /:
```
### ๐น Login to Docker
```bash
docker login
```
### ๐น Logout
```bash
docker logout
```
---
## ๐งน 4. Docker Cleanup
### ๐น Remove All Stopped Containers
```bash
docker container prune
```
### ๐น Remove All Unused Images
```bash
docker image prune
```
### ๐น Remove Everything (containers + images + volumes)
```bash
docker system prune -a
```
Add `-f` to skip confirmation:
```bash
docker system prune -a -f
```
---
## ๐ 5. Dockerfile Reference
```dockerfile
# Start with base image
FROM node:18
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy rest of the files
COPY . .
# Expose the port
EXPOSE 3000
# Start command
CMD ["npm", "start"]
```
---
## ๐งช 6. Docker Compose Basics
### ๐น Sample `docker-compose.yml`
```yaml
version: '3'
services:
backend:
build: .
ports:
- "5000:5000"
depends_on:
- mongo
mongo:
image: mongo
ports:
- "27017:27017"
```
### ๐น Commands
- Start services:
```bash
docker-compose up
```
- Run in background:
```bash
docker-compose up -d
```
- Stop services:
```bash
docker-compose down
```
---
## ๐ 7. DockerHub Best Practices
### ๐ธ Repositories
- Public: visible to everyone
- Private: only for you (1 free private repo on DockerHub free tier)
### ๐ธ Tips
- Always tag images before pushing.
- Use meaningful names and versions.
- Keep images light and clean.
---
## ๐ง Useful Flags Cheat
| Command | Flags | Description |
|--------|--------|-------------|
| `docker run` | `-d`, `-p`, `--name`, `-it` | Background, port, name, interactive |
| `docker ps` | `-a` | Show all containers |
| `docker build` | `-t` | Tag the build |
| `docker rmi` | `-f` | Force remove |
| `docker system prune` | `-a`, `-f` | Remove everything |
---
## โ
Recommended Flow for Uploading a Project to DockerHub
```bash
docker build -t swayamgupta12345/learn:latest .
docker login
docker push swayamgupta12345/learn:latest
```
---
## ๐งพ Extras
### ๐น Check Container Logs
```bash
docker logs
```
### ๐น Execute Command in Running Container
```bash
docker exec -it bash
```
### ๐น Save Image as Tar File
```bash
docker save -o myapp.tar swayamgupta12345/learn:latest
```
---