Learn how to install Docker on Ubuntu 24.04 with this step-by-step guide. Follow the instructions to set up Docker quickly and efficiently, ensuring your applications
Discover the 25 basic Docker commands every beginner needs to know. This comprehensive guide covers everything from pulling images to managing containers, complete with examples and a summary table.
Docker has revolutionized the way developers build, ship, and run applications. It simplifies the process by encapsulating applications and their dependencies into containers. For beginners, mastering Docker commands is crucial for efficient container management. In this blog post, we’ll dive into 25 basic Docker commands that every beginner should know. These commands will help you get started with Docker and manage your containers effectively.
Before diving into Docker commands, ensure you have the following:
|
With these prerequisites in place, you are ready to explore the fundamental Docker commands.
1. Docker Version |
To verify your Docker installation, use the docker version
command. This command displays detailed information about the Docker client and server versions.
docker --version
2. Docker Info |
Get a comprehensive overview of your Docker installation with the docker info
command. It provides details about the Docker installation, including the number of containers, images, and the storage driver.
docker info
3. Pull an Image |
To download an image from Docker Hub, use the docker pull
command. For instance, to pull the latest Ubuntu image, run:
docker pull ubuntu:latest
4. List Images |
You can list all the images stored on your machine with the docker images
command. This helps you keep track of available images.
docker images
5. Remove an Image |
To delete an image from your local machine, use the docker rmi
command followed by the image ID or name.
docker rmi ubuntu:latest
6. Create a Container |
Use the docker create
command to create a new container from an image. This does not start the container immediately.
docker create --name mycontainer ubuntu
7. Start a Container |
To start a created container, use the docker start
command followed by the container ID or name.
docker start mycontainer
8. Run a Container |
The docker run
command creates and starts a container in one step. It is widely used for running containers.
docker run -it ubuntu
9. Stop a Container |
If you need to stop a running container, use the docker stop
command followed by the container ID or name.
docker stop mycontainer
10. Remove a Container |
To delete a stopped container, use the docker rm
command.
docker stop mycontainer
11. List Containers |
You can list all running containers with the docker ps
command. To include stopped containers, add the -a
flag.
docker ps
docker ps -a
12. Inspect a Container |
To get detailed information about a container, use the docker inspect
command followed by the container ID or name.
docker inspect mycontainer
Photo by admingeek from Infotechys
13. View Container Logs |
Access the logs of a running container with the docker logs
command. This is helpful for debugging purposes.
docker logs mycontainer
14. Execute Commands in a Running Container |
Use the docker exec
command to run a command inside an active container.
docker exec -it mycontainer /bin/bash
15. Copy Files from a Container |
To copy files from a container to your local machine, use the docker cp
command.
docker exec -it mycontainer /bin/bash
16. Commit a Container |
Create a new image from a container’s changes with the docker commit
command.
docker commit mycontainer mynewimage
17. Tag an Image |
Use the docker tag
command to tag an image with a new name or tag.
docker tag mynewimage myrepository/mynewimage:latest
18. Push an Image |
To upload an image to a Docker registry, use the docker push
command.
docker push myrepository/mynewimage:latest
19. Login to Docker Hub |
Before pushing images, you need to log in to Docker Hub using the docker login
command.
docker login
20. Logout from Docker Hub |
To log out from Docker Hub, use the docker logout
command.
docker logout
21. Build an Image |
Create a new image from a Dockerfile using the docker build
command.
docker build -t mynewimage .
22. Save an Image to a Tar Archive |
Use the docker save
command to save an image to a tar archive.
docker save -o myimage.tar mynewimage
23. Load an Image from a Tar Archive |
To load an image from a tar archive, use the docker load
command.
docker load -i myimage.tar
24. Network List |
To list all networks, use the docker network ls
command.
docker network ls
25. Prune Docker System |
Clean up unused containers, networks, images, and build cache with the docker system prune
command.
docker system prune
Summary Table of Commands
|
Mastering these basic Docker commands will significantly enhance your ability to manage containers efficiently. Whether you are pulling images, creating and running containers, or inspecting and troubleshooting, these commands form the foundation of Docker management. Practice these commands to become proficient in Docker and streamline your development workflow.
Did you find this article useful? Your feedback is invaluable to us! Please feel free to share your thoughts in the comments section below.
Related Posts
Learn how to install Docker on Ubuntu 24.04 with this step-by-step guide. Follow the instructions to set up Docker quickly and efficiently, ensuring your applications
Learn how to install and configure Docker Swarm on RHEL 9 or CentOS 9 with our comprehensive guide. Follow step-by-step instructions and examples to deploy
Troubleshooting made easy: Learn fixes and solutions for common Docker errors in this comprehensive guide. Enhance your container management skills and ensure seamless deployments. Table