Thursday, March 13, 2025

📢 Essential Docker Commands – Mastering the Basics

 


Essential Docker Commands – Mastering the Basics


Mastering Docker commands is essential for efficiently managing containers, images, networks, and volumes. These commands help you interact with Docker and streamline the containerization process.


🌍 Shape Your Future with AI & Infinite Knowledge...!!

🌐 Want to Generate Text-to-Voice, Images & Videos? 👉 http://www.ai.skyinfinitetech.com 📚 Read In-Depth Tech & Self-Improvement Blogs 👉 http://www.skyinfinitetech.com ▶ Watch Life-Changing Videos on YouTube 👉 https://www.youtube.com/@SkyInfinite-Learning 🔥 Transform Your Skills, Business & Productivity – Join Us Today! 🔥



🔹 Basic Docker Commands

1️⃣ Check Docker Version


docker --version

Displays the installed Docker version.


2️⃣ Pull an Image from Docker Hub


docker pull nginx

Downloads an image from the Docker Hub registry.


3️⃣ Run a Container


docker run -d -p 8080:80 nginx

Runs an Nginx container in detached mode (-d) and maps port 8080 on the host to port 80 inside the container.


4️⃣ List Running Containers


docker ps

Shows active containers. Add -a to see all containers (including stopped ones).


5️⃣ Stop a Running Container


docker stop <container_id>

Stops a container gracefully.


6️⃣ Restart a Container


docker restart <container_id>

Restarts a stopped or running container.


7️⃣ Remove a Container


docker rm <container_id>

Deletes a stopped container permanently.


8️⃣ Remove All Stopped Containers


docker container prune

Deletes all stopped containers at once.


9️⃣ Remove an Image


docker rmi <image_name>

Removes an unused image from the system.


10️⃣ List All Docker Images


docker images

Shows all downloaded Docker images.


11️⃣ Check Container Logs


docker logs <container_id>

Displays logs from a running container.


12️⃣ View Running Processes Inside a Container


docker top <container_id>

Shows processes running inside a container.


13️⃣ Execute a Command Inside a Running Container


docker exec -it <container_id> bash

Opens an interactive shell inside a running container.


14️⃣ Copy Files from a Running Container to Host

docker cp <container_id>:/path/to/file /destination/path

Copies files from a container to the host system.


15️⃣ Inspect Detailed Information About a Container


docker inspect <container_id>

Displays low-level information about a container or image.


16️⃣ Check Disk Usage by Docker Objects


docker system df

Shows disk usage of images, containers, and volumes.


17️⃣ Remove Unused Images, Containers, and Networks


docker system prune -a

Cleans up all unused Docker objects, including dangling images.



📢 Next Up: Writing Dockerfiles – Building Custom Images

No comments:

Post a Comment

Terraform State Deep Dive: Why it's Crucial and How to Manage It

Terraform State Deep Dive: Why it's Crucial and How to Manage It ...