How to use docker CLI for beginner

Run a Container

docker run <image_name>

Run a Container in Detached Mode (Background)

docker run -d <container_id>

List Running Containers

docker ps

List Containers (including stopped ones)

docker ps -a

Start a Container

docker start <container_id>

Stop a Container

docker stop <container_id>

Remove a stopped Container

docker rm <container_id>

List Images

docker images 

Pull an Image from Docker Hub

docker pull <image_name>

Remove an Image

docker rmi <image_name>

View Logs of a Running Container

docker logs <container_id>

Log into a Running Container (-it=interactive, tty)

docker exec -it <container_id> /bin/bash

Execute a command in a Container

docker exec <container_id> ls -l

Remove All Stopped Containers and Images

docker system prune -a