Docker is a set of platform as a service products ( PaaS) that use OS-level virtualization to deliver software in packages called containers. Developers can build, share, and run modern applications using docker.
Here are top 20 most used docker commands that you must know.
1. docker version
Displays the Docker version information.
Example: To display the Docker version information in your terminal, run the following command:
docker version
2. docker search
Searches the Docker Hub registry for an image.
Example: To search for the nginx image on Docker Hub, run the following command in your terminal:
docker search nginx
3. docker pull
Pulls an image from a registry to the local machine.
Example: To pull the nginx image from Docker Hub, run the following command in your terminal:
docker pull nginx
4. docker run
Runs a command in a new container.
Example: To start a new container using the nginx image and map port 80 of the container to port 8080 of the host, run the following command in your terminal:
docker run -p 8080:80 nginx
5. docker ps
Lists the running containers.
Example: To list all the running containers on your system, run the following command in your terminal:
docker ps
6. docker stop
Stops one or more running containers.
Example: To stop a running container with the ID 123456, run the following command in your terminal:
docker stop 123456
7. docker restart
Restarts one or more containers.
Example: To restart a container with the ID 123456, run the following command in your terminal:
docker restart 123456
8. docker kill
Sends a SIGKILL signal to a running container, killing it.
Example: To kill a running container with the ID 123456, run the following command in your terminal:
docker kill 123456
9. docker exec
Runs a command in a running container.
Example: To run a command ls inside a running container with the ID 123456, run the following command in your terminal:
docker exec 123456 ls
10. docker login
Logs in to a Docker registry.
Example: To log in to Docker Hub, run the following command in your terminal:
docker login
11. docker commit
Creates a new image from a containers changes.
Example: To create a new image from a container with the ID 123456, run the following command in your terminal:
docker commit 123456 myimage:v1.0
12. docker push
Pushes an image to a registry.
Example: To push the myimage:v1.0 image to Docker Hub, run the following command in your terminal:
docker push myusername/myimage:v1.0
13. docker network
Manages Docker networks.
Example: To create a new network called mynetwork, run the following command in your terminal:
docker network create mynetwork
14 docker history
Shows the history of an image.
Example: To display the history of the nginx image, run the following command in your terminal:
docker history nginx
15. docker rmi
Removes one or more images.
Example: To remove an image with the ID 123456, run the following command in your terminal:
docker rmi 123456
16. docker ps -a
Lists all containers, including stopped containers.
Example: To list all the containers, including the stopped ones, run the following command in your terminal:
docker ps -a
17. docker copy
Copies files or folders between a container and the local filesystem.
Example: To copy a file myfile.txt from a container with the ID 123456 to your local filesystem, run the following command in your terminal:
docker cp 123456:/path/to/myfile.txt /path/to/destination
18. docker logs
Shows the logs of a container.
Example: To show the logs of a container with the ID 123456, run the following command in your terminal:
docker logs 123456
19. docker volume
Manages Docker volumes.
Example: To create a new volume called myvolume, run the following command in your terminal:
docker volume create myvolume
20. docker logout
Logs out from a Docker registry.
Example: To log out from Docker Hub, run the following command in your terminal:
docker logout