Top 17 Docker Commands List with Examples

blog_auth Blog Author

StarAgile

published Published

Aug 08, 2021

views Views

4,047

readTime Read Time

20 mins

What Are Docker Commands?

Docker is one of the prominent virtualization tools that enables close integration with the host server. It indicates OS virtualization. The majority of developers choose docker because OS interfaces are intertwined with developers. Optimization of the performance of the system starts with the understanding of docker commands. They are extremely lightweight virtual machines.

Docker has undoubtedly transformed the way development teams working. It enables you with a mechanism of moving code between servers, improving security, and decoupling applications. So if you don't currently use Docker in your development process, now it's time to take a careful look.

The objective of Docker is to design and implement compute images and also to deploy them in containers. As a result, the most relevant commands perform this function and reveal this information.

To get started with Docker functions, you must first decide whether you interact with images or containers.

As soon as you have a clear understanding of the issue, you can identify the necessary instructions.

The docker client can interpret several commands. Whether at the development or operations level, anyone participating in software development will benefit significantly from DevOps training. 

Why Docker Commands Are Used

Docker is a commonly used containers solution that developers and operational processes used to construct and automate the deployment of compact containers on virtual machines. This is done to ensure that programs run smoothly in a variety of situations.

Docker has transformed the way programmers and engineers carry out their work. It provides a method for moving code between platforms, improving security, and decoupling dependencies between different applications. Therefore, if you haven't already included Docker in your planning process, now is the time to use it. Docker simplifies the development process by enabling developers to work inconsistent settings while utilizing the storages to host their applications. Containers are an excellent choice for continuous integration and delivery (CI/CD) operations.

Docker's container-based infrastructure enables workloads to be highly customizable. Based on the environment, the Docker container can be deployed on a developer's workstation, on physical or virtual servers in network infrastructure, on cloud providers, or in various settings.

Dockers' accessibility and lightweight functionality make it very simple to effectively manage workflows and scale apps and services in almost real-time, as dictated by business demands. Docker is a compact and fast container management system. It is a realistic, cost-effective solution to allow you to maximize the utilization of your computer power for business purposes. Docker is ideal for high-density environments and small and medium-sized deployments that require more performance with minimal resources.

Docker's flexibility enables enterprises to build and maintain systems across several platforms. This improves operational efficiency and developmental productivity by allowing the apps to run smoothly across multiple servers or on a single server. DevOps course certification enables continuous reviewing throughout the software development, allowing for a holistic perspective. This performs more stable and, ultimately, a higher-quality product for the end-user.

You can enroll for the DevOps certification course to gain job advantages depending upon your expertise and skillset.

Top 17 Docker Basic Commands With Example

Docker cheat sheet

The following are Top 17 docker basic commands to experiment with on the command line. 

1. docker run

Docker run is likely the essential tool on the Docker commands list because it allows you to run containers. It creates a new container and then begins it with the specified line. It's the equivalent of running docker create followed by docker start.

Application: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Example: the Hello World docker run

Docker Hub is used in this case to download, develop, and execute the docker named "hello-world." Explore with it.

2. docker create

Although this command makes a new container and sets it to perform the specified program, it does not run the chosen program. STDOUT is used to print the ID. This is equivalent to docker run, except that no container is launched. It can be reactivated at any time by running the command prompt docker start <container id>.

This is advantageous if you aim to build and set up a container for later execution.

Usage: DOCKER CREATE [OPTIONS] USE IMAGE [COMMAND] [ARG...]

Example: docker create hello-world

The hello-world container will be downloaded and created but not activated.

3. docker start

This command starts a container, whether one that has been established with docker create or previously closed. 

Application: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Example: docker start hello-world

4. docker stop

This command terminates a running container.

Application: docker stop [OPTIONS] CONTAINER

Example: docker stop hello-world

This case closes the last example's container. Docker start can be used to restart it if it has stopped working.

5. docker ps

This command displays a list of accessible Docker. Only active containers are shown by default, but you can use parameters such as-a to obtain a list of all available docker containers. 

Application: docker ps [OPTIONS]

Example: docker ps -a

The preceding command returns a list of all containers on the systems.

6. docker rm

It removes a container from the current location. After listing existing containers with docker ps, you will use this command to terminate one or more of these.

Application: docker rm [OPTIONS] CONTAINER [CONTAINER...]

Example: docker rm -f redis

This example removes the ‘redis' container from the system. The -f flag compels the action, indicating that the container will first get a SIGKILL command.

7. docker rmi

rmi is an acronym for image removal. Like docker rm, it removes the docker image instead of an active image.

Application: docker rmi [OPTIONS] IMAGE [IMAGE...]

Example: docker rmi test

This example will delete the filename 'test' from the image. To obtain a list of ideas and their associated ids, run the docker images program.

8. docker login

It allows you to log onto a docker registry. This statement can be used to log in to any business or government registry. This is likely to be used for logging in to Docker Hub.

Application: docker login [OPTIONS] [SERVER]

Example: localhost docker login:8080

By selecting the server name, we can log in to the self-hosted registration. Alternatively, you can use docker login to access your Docker Hub registration system.

9. docker tag

A tag named TARGET IMAGE that points to the source image, SOURCE IMAGE is created with the help of this function.

Application: docker tag SOURCE IMAGE [:TAG] TARGET IMAGE[:TAG]

Example: docker tag 7d9495d03763 maryatdocker/docker-whale:latest

Here, we're adding the tag "latest" to a local image with the ID "7d9495d03763" in the "maryatdocker/docker-whale" collection.

10. docker push

The docker push function is used to publish your copies to Docker Hub or another repository. It is a critical component of the implementation process and must be used in collaboration with docker tag and docker login to function effectively.

Application: docker push [OPTIONS] NAME[: TAG]

Example: docker push maryatdocker/docker-whale

This example will add the image that we previously tagged to the storage.

11. docker exec

You can enter the docker container using the command below to run bash commands or update the configuration. This command is used to gain access to the container that is currently operating. Access the docker container and execute commands within it.

Application: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Example: docker exec -it ubuntu_bash bash

This example will start a new Bash account in the ubuntu_bash container.

12. docker commit

It can be advantageous to commit changes to a container's files or settings to a new image. It allows you to debug an interactive container or export a functional dataset to a different server. The commit action excludes data from volumes mounted within the container.

Application: docker commit [OPTIONS] CONTAINER [REPOSITORY [: TAG]]

Example: docker commit 09ca6feb6efc geekflare/httpd_image

In this example, geekflare serves as the username, and httpd_image serves as the image's name.

13. docker kill

Docker kill is a subcommand that terminates one or more containers. The container's primary process is completed with the SIGKILL signal (by default) or with the --signal option. You can kill a container with ID, ID prefix or name of the container.

Application: docker kill [OPTIONS] CONTAINER [CONTAINER...]

Example: docker kill my_container

The example delivers the default KILL as the username signal to the image's name my_container.

14. docker inspect

Docker inspect offers extensive information about Docker-controlled constructs. The docker checks command outputs a JSON file containing all of the information about the docker container.

Application: docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Example: docker inspect --format='{{ .NetworkSettings.IPAddress }}' containerID

As shown here, you can obtain information about the container's networking component (IP address).

15. docker pull

This command retrieves pictures from the docker repository. After searching for an image, you can pull it from the Docker registry if it is accessible. If you've created a local registry, you can mention its path to retrieve data from. A registry path is identical to a URL, except it does not contain an https:// protocol specifier.

Application: docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Example: docker pull myregistry.local:5000/testing/test-image

The command pulls the testing/test-image from a local registry (Docker Hub) that listens on port 5000 (myregistry.local:5000)

16. docker build

This command is used to create an image from a specific docker file.

Docker images are created using the docker build command, which takes a Dockerfile and a "context" as input. The context of a build is a collection of files located in the provided PATH or URL. The build process can use any of the context files.

Application: docker build [OPTIONS] PATH | URL | -

Example: docker build https://github.com/docker/rootfs.git#container:docker

Here, the first part specifies the location of the reference that Git will check out, which can be a branch, a tag, or a remote reference. The second part denotes a subdirectory within the repository that will serve as the build context.

17. docker info

This tool displays information about the Docker installation on the entire system. Retrieve precise information about the docker installation on your system, such as the kernel version, the number of containers and images, and so on.

Application: docker info [OPTIONS] 

Example: docker -D info

All Docker commands are caused to issue debug information using the global -D option.

DevOps Certification

Training Course

100% Placement Guarantee

View course
 

Conclusion:

Docker has established a strong presence in developing trends. You must become familiar with its command prompt as soon as possible. The first step is to become proficient with the docker command prompt.

Before you go into DevOps online course, you need to determine what you'd like to accomplish by implementing it.

If you're driven to your IT profession, adding a DevOps certification to your years of expertise is an excellent way to stay current in an ever-changing market. You can accomplish additional work with DevOps automation skills and provide more excellent operational assistance.

 

Share the blog
readTimereadTimereadTime
Name*
Email Id*
Phone Number*

Keep reading about

Card image cap
DevOps
reviews5350
Top 10 DevOps programming languages in 20...
calender18 May 2020calender20 mins
Card image cap
DevOps
reviews4508
Top 9 Devops Engineer Skills
calender18 May 2020calender20 mins
Card image cap
DevOps
reviews4720
Best DevOps Tools in 2024
calender18 May 2020calender20 mins

Find DevOps Certification Training in Top Cities

We have
successfully served:

3,00,000+

professionals trained

25+

countries

100%

sucess rate

3,500+

>4.5 ratings in Google

Drop a Query

Name
Email Id*
Phone Number*
City
Enquiry for*
Enter Your Query*