Reference Link:
https://upessocs.github.io/#dir=/Lectures/Containerization%20and%20DevOps/Theory/Containerization%20and%20DevOps/Theory/&file=011%20Docker%20basic%20commands.md





wsl
docker version
docker info
List local images
sudo docker images
Show all images
docker images -a
Only image IDs
docker images -q
sudo docker pull ubuntu
sudo docker pull ubuntu:22.04sudo docker images
The container starts and immediately exits
sudo docker run ubuntu
Show all running containers
sudo docker ps
Show all containers (running+stopped+exited)
sudo docker ps -a
Show only container IDs
sudo docker ps -q
Filter ubuntu related containers
sudo docker ps -a | grep ubuntu
—
it= interactive terminal
you are inside ubuntu container
sudo docker run -it ubuntu
now you are inside container
pwd
Docker containers have their own isolated filesystem
/ is the root directory of the container
It is NOT connected to your Windows folders by default
ls
You are now inside a real Linux environment.
wsl
sudo docker ps
The container is running
exit
Exiting shell = container stops if no background process.
sudo docker ps
sudo docker ps -a
The container is stopped.
sudo docker images
sudo docker rmi 1b44 (error: The Ubuntu image is still linked to stopped containers, Docker protects images from deletion if containers exist)
sudo docker rmi 1b44 -f (force remove)
sudo docker ps -a (shows all containers (running + stopped), Containers still exist, but their image has been removed, they cannot be restarted properly now)
sudo docker ps
sudo docker start 1519b
sudo docker ps -a
sudo docker restart eae3