Docker

10 Basic Docker Commands You Must Learn

Docker is a well-established open-source platform for developers to build, deploy and ship applications. The Docker community provides Docker Desktop as well as Docker CLI. Additionally, Docker CLI offered numerous useful commands to build, deploy, share the project publicly, and manage Docker components such as Docker containers, Docker images, Docker registries, and many more.

This blog will discuss the ten basic Docker commands users must learn:

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:

$ docker build -t dockerdemo .

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:

$ docker run -it dockerdemo

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:

$ docker ps -a

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:

$ docker create --name docker-container dockerdemo

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”:

$ docker version

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:

$ docker search MYSQL

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:

$ docker commit b142e7e0d5c2 rafia098/python-image:3.6

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>”:

$ docker push rafia098/python-image:3.6

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:

$ docker history python-image

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>”:

$ docker pull rafia098/python-image:3.6

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.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.