This blog will discuss the ten basic Docker commands users must learn:
- Docker build
- Docker run
- Docker ps
- Docker create
- Docker version
- Docker search
- Docker commit
- Docker push
- Docker history
- Docker pull
Command 1: Docker “build”
The “docker build” command is used to build or generate a new Docker image by utilizing the Dockerfile. Docker images instruct containers on deploying, building, and shipping the program. Moreover, Docker’s “build” command also supports the different options to perform different functions, such as the “-t” option used to specify the “name” of the image.
To build or generate the docker image, the “docker build <option> <image-name> .” command is used as follows:
Command 2: Docker “run”
The “docker run” command is used to execute the Docker image that instructs the Docker container to deploy the application. The syntax used to process the Docker “run” command is the “docker run <option> <image-name>”.
It also supports the different options to function differently, such as “-it”. It runs the Docker container in interactive mode and allocates the container to the “TTY- pseudo” terminal. To utilize the Docker “run” command, check out the provided command:
Command 3: Docker “ps”
The “docker ps” command is a more basic command of the Docker platform used to list down the Docker containers, view container status, docker image, ports, and so on. It also supports different options, and the “-a” is frequently used to list down all container details.
To use Docker “ps”, check out the provided command:
Command 4: Docker “create”
The Docker “create” command is used to create and build the Docker container. The syntax used to run this command is “docker create <option> <container> <docker-image>”.
To utilize the “docker create” to build a new container, follow the mentioned command. Here, the “–name” option is used to create a container by specific name:
Command 5: Docker “version”
The Docker “version” command is used to check the Docker version and other information related to Docker platforms, such as Build, OS/Arc, and many more. The two options supported by the “docker version” command are “–format” and “–kubeconfig”:
Command 6: Docker “search”
Docker “search” is another basic and widely used command to search public images, such as MySQL and Ubuntu, from Docker Hub.
To search for any public image, utilize the “docker search <image-name>” command:
Command 7: Docker “commit”
Docker “commit” is another well-known Docker command used to manipulate and save the Docker container file and set or save them in the Docker image or may recreate the Docker image. The syntax of Docker “commit” is “docker commit <container id> <repository<:tag>>”.
To utilize the “docker commit”, follow up the provided command:
Command 8: Docker “push”
The Docker “push” command is used to push the changes from the local Docker registry to the server registry, such as DockerHub. It is utilized to import the Docker images on the DockerHub registry. The syntax for Docker “push” is “docker push <Username>/<Image-name>:<Tag/Version>”:
Command 9: Docker “history”
Docker “history” command is used to display the Docker images layers as well as references. The Docker images are built through a Dockerfile that contains a series of instructions or commands. Then, these commands are executed in layers, and the “docker history” command displays the layer’s history.
To view the history of the Docker image, utilize the “docker history <image-name>” command:
Command 10: Docker “pull”
The Docker “pull” command is another famous and widely used Docker command. It allows developers to pull the Docker images from remote to local machines, such as pulling Ubuntu docker images from Docker Hub to the local machine.
To utilize the Docker “pull”, use the “<docker pull <Username>/<Image-name>:<Tag/Version>”:
We have discussed the ten basic commands of the Docker platform that the user must learn.
Conclusion
Docker CLI offers numerous useful commands to build and deploy projects. The ten basic commands that Docker users must learn are Docker “build”, Docker “run”, Docker “ps”, Docker “create”, Docker “version”, Docker “search”, Docker “commit”, Docker “push”, Docker “history”, and Docker “pull”. We have demonstrated ten basic commands the users must learn.