blogcheatsheetmisc

docker

Images

docker images
List all images
docker build -t name:tag .
Build an image from Dockerfile
Example: docker build -t myapp:1.0 .
docker build -t <image_name> . –no-cache
Build an Image from a Dockerfile without the cache
docker pull <image>
Pull an image from registry
docker rmi <image>
Remove an image
docker tag <source> <target>
Tag an image
docker image prune
Remove all unused images

Containers

docker ps
List running containers
docker ps -a
List all containers (including stopped)
docker run -d -p host:container image
Run container in detached mode with port mapping
Example: docker run -d -p 8080:80 nginx
docker run -it --rm -v /path/on/host:/path/in/container <image> sh
Run container in interactive mode with volume mount. Remove container once the container is stopped
docker exec -it <container> /bin/sh
Executes an interactive shell inside an already running container
docker stop <container>
Stop a running container
docker start <container>
Start a stopped container
docker rm <container>
Remove a container
docker exec -it <container> bash
Execute interactive bash in container
docker logs <container>
View container logs
docker logs -f <container>
Follow container logs
docker inspect <container>
To inspect a running <container_name> (or <container_id>)
docker container stats
View resource usage stats
docker port <container>
Show port binding to host

System

docker system prune -a
Remove all unused containers, networks, images
docker system df
Show docker disk usage
docker info
Display system-wide information

awk

awk '{print $1}'
Print first column
awk '{print $NF}'
Print last column

git

Common

git status
Show working tree status
git add <file>
Stage changes for commit
git commit -m 'message'
Commit staged changes
git push origin <branch>
Push commits to remote
git pull
Fetch and merge remote changes
git branch -a
List all branches
git checkout -b <branch>
Create and switch to new branch
git merge <branch>
Merge branch into current branch
git log --oneline
Show commit history (compact)
git diff
Show unstaged changes
git reset --hard HEAD
Discard all local changes
git stash
Temporarily save changes
git stash pop
Restore stashed changes

ls-files

git ls-files --others --exclude-standard
To list untracked files

sed

sed 's/pattern/replacement/'
Replace first occurrence per line
Example: sed 's/foo/bar/' file.txt
sed 's/pattern/replacement/g'
Replace all occurrences
sed -i 's/pattern/replacement/g'
Edit file in-place
sed -n '5,10p'
Print lines 5 to 10
sed '/pattern/d'
Delete lines matching pattern
sed '5d'
Delete line 5
sed -n '/pattern/p'
Print only matching lines

grep

grep 'pattern' file
Search for pattern in file
grep -r 'pattern' dir/
Recursively search directory
grep -i 'pattern' file
Case-insensitive search
grep -v 'pattern' file
Invert match (exclude pattern)
grep -n 'pattern' file
Show line numbers
grep -c 'pattern' file
Count matching lines
grep -A 3 'pattern' file
Show 3 lines after match
grep -B 3 'pattern' file
Show 3 lines before match
grep -E 'pattern1|pattern2' file
Extended regex (OR)

ss

ss -tlnp
List all open TCP connections