Check Docker Installation Details Part - 3
Exploring Basic Docker Commands Now that we've verified our Docker installation works correctly (Part-2), let's explore some basic Docker commands that will help you manage containers and images. Running an Interactive Container Unlike the hello-world container that runs and exits immediately, we can run containers interactively. 1.Let's run an Ubuntu container and interact with its shell: docker run -it ubuntu bash This command: • -i keeps STDIN open • -t allocates a pseudo-TTY (terminal) • ubuntu is the image name. • bash is the command to run inside the container. Once the container starts, you'll be at a bash prompt inside the container. The prompt shows you're logged in as root in the container. The alphanumeric string is the container ID. 2.Try running some Linux commands inside the container: cat /etc/os-release This will display information about the Ubuntu version running in the container: 3.When you're done exploring, exit the container by typing: exit This will return you to your host terminal. Container Lifecycle Management 4.Let's explore how to manage the lifecycle of a container. First, we'll start a container in detached mode: docker run -d --name web nginx This command: • -d runs the container in detached mode (in the background) • --name web assigns the name "web" to the container • nginx is the image to use. You'll see a long container ID printed on the screen. 5.Now, let's check that the container is running: docker ps You should see the nginx container running. 6.To stop the container: docker stop web 7.Verify it's stopped: docker ps 8.The container should no longer appear in the list of running containers. To see all containers including stopped ones: docker ps -a You should the nginx containers in the stopped state. 9.To start the container again and check container status: docker start web docker ps 10.to remove a container when you no longer need it: docker rm web 11.Error response from daemon: cannot remove container "/web": container is running stop the container before removing. First stop the running container then remove and check: docker stop web docker rm web Command: docker ps -a You should see the web container not available. Managing Docker Images Let's explore how to manage Docker images. To list all images: 12.Let’s check the docker images available of your system. docker images You should see at least the hello-world and nginx images. 13.To remove an image when you no longer need it: docker rmi hello-world Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container be8b92819418 is using its referenced image 74cc54e27dc4. Note that you can't remove images that are being used by containers (even stopped ones). You'll need to remove those containers first. 14.Let’s remove the hello-world container then remove hello-world image: Command:docker ps -a Command: docker rmi hello-world Command: docker images You should see the hello-world image not available in the images list. Docker System Information To check disk space used by Docker (containers, images, volumes): 15.Let’s check disk space used by docker: docker system df This will show a summary of disk usage. 16.To get more detailed information: docker system df -v This will show a breakdown of each image and container and their sizes. LinkedIn: https://linkedin.com/in/kamrul-dev GitHub: https://github.com/kamrul-dev Related Keywords: How to verify Docker installation on your system, Checking Docker version and system info via CLI, Confirming Docker is properly installed on Linux/Mac/Windows, Commands to check Docker installation status, Troubleshooting Docker setup issues, Kamrul Hasan DevOps Engineer, DevOps tips by Kamrul Hasan, Kamrul Hasan Docker tutorials, Learn DevOps with Kamrul Hasan, Kamrul Hasan automation expert, Kamrul Hasan cloud and containers, CI/CD pipelines by Kamrul Hasan, Kamrul Hasan Kubernetes & Docker,

Exploring Basic Docker Commands
Now that we've verified our Docker installation works correctly (Part-2), let's explore some basic Docker commands that will help you manage containers and images.
Running an Interactive Container
Unlike the hello-world container that runs and exits immediately, we can run containers interactively.
1.Let's run an Ubuntu container and interact with its shell:
docker run -it ubuntu bash
This command:
• -i keeps STDIN open
• -t allocates a pseudo-TTY (terminal)
• ubuntu is the image name.
• bash is the command to run inside the container.
Once the container starts, you'll be at a bash prompt inside the container. The prompt shows you're logged in as root in the container. The alphanumeric string is the container ID.
2.Try running some Linux commands inside the container:
cat /etc/os-release
This will display information about the Ubuntu version running in the container:
3.When you're done exploring, exit the container by typing:
exit
This will return you to your host terminal.
Container Lifecycle Management
4.Let's explore how to manage the lifecycle of a container. First, we'll start a container in detached mode:
docker run -d --name web nginx
This command:
• -d
runs the container in detached mode (in the background)
• --name
web assigns the name "web"
to the container
• nginx is the image to use.
You'll see a long container ID
printed on the screen.
5.Now, let's check that the container is running:
docker ps
You should see the nginx container running.
6.To stop the container:
docker stop web
7.Verify it's stopped:
docker ps
8.The container should no longer appear in the list of running containers. To see all containers including stopped ones:
docker ps -a
You should the nginx containers in the stopped state.
9.To start the container again and check container status:
docker start web
docker ps
10.to remove a container when you no longer need it:
docker rm web
11.Error response from daemon:
cannot remove container "/web"
: container is running stop the container before removing. First stop the running container then remove and check:
docker stop web
docker rm web
Command: docker ps -a
You should see the web container not available.
Managing Docker Images
Let's explore how to manage Docker images. To list all images:
12.Let’s check the docker images available of your system.
docker images
You should see at least the hello-world and nginx images.
13.To remove an image when you no longer need it:
docker rmi hello-world
Error response from daemon:
conflict: unable to remove repository reference "hello-world" (must force) - container be8b92819418
is using its referenced image 74cc54e27dc4.
Note that you can't remove images that are being used by containers (even stopped ones). You'll need to remove those containers first.
14.Let’s remove the hello-world container then remove hello-world image:
Command:docker ps -a
Command: docker rmi hello-world
Command: docker images
You should see the hello-world image not available in the images list.
Docker System Information
To check disk space used by Docker (containers, images, volumes):
15.Let’s check disk space used by docker:
docker system df
This will show a summary of disk usage.
16.To get more detailed information:
docker system df -v
This will show a breakdown of each image and container and their sizes.
LinkedIn: https://linkedin.com/in/kamrul-dev
GitHub: https://github.com/kamrul-dev
Related Keywords:
How to verify Docker installation on your system,
Checking Docker version and system info via CLI,
Confirming Docker is properly installed on Linux/Mac/Windows,
Commands to check Docker installation status,
Troubleshooting Docker setup issues,
Kamrul Hasan DevOps Engineer,
DevOps tips by Kamrul Hasan,
Kamrul Hasan Docker tutorials,
Learn DevOps with Kamrul Hasan,
Kamrul Hasan automation expert,
Kamrul Hasan cloud and containers,
CI/CD pipelines by Kamrul Hasan,
Kamrul Hasan Kubernetes & Docker,