Top 25+ Docker Commands: A Guide of Docker Commands with Examples [2023]

Docker – ‘A better way to build apps’, as stated on its website, is an open-source platform for building apps and microservices. The catch here is the automated deployment of your app in a container by OSlevel virtualization provided by Dockers. Dockers are better than VMs as you can do away with the additional costs of maintaining and starting the latter. By deploying your app and its dependencies (i.e., the pre-requisite apps for its proper functioning) in a container, your app becomes portable during all the development and testing phases. Moreover, the isolated apps eliminate conflicts, enable team collaboration, and reduce the time-to-market. 

 

When Do You Need to Use a Docker?

  • For replicating the environment on your server, while running your code locally on your laptop
  • For Docker CI/CD during numerous development phases (dev/test/QA)
  • For distributing your app’s OS with a team, and as a version control system.

How Do You Setup a Docker Locally

  • Download a Docker edition and the Docker Toolbox
  • Make sure your BIOS has Virtualization Technologies, AMD-V, or KVM enabled
  • Install the Extension Pack in the Oracle VirtualBox.
  • Run the Setup

How Do You Use a Docker?

The most significant advantage of VMs is that they create snapshots that can be revisited instantly later. Docker containers enhance the lightweight process virtualization by being OS-independent and using the Linux Kernel’s functionality. They are made from Docker images – like snapshots. Docker images are created using a Docker file which can be customized or used as is. The default execution driver for creating a docker container is ‘libcontainer’. Docker Hub can be used to search docker images and see how they have been built. 

  • To create a Docker container, download the ‘hello world’ image by typing the following command in the terminal – $ docker run the hello world 
  • To check the number of images on your system, use the following command – $ docker images 
  • For searching an image in the Docker Hub – $ docker search <image> 

Here’s a List of Docker Commands

  • docker run: Executes command in a new container. 
  • docker ps: Lists running containers. 
  • docker ps -a: Lists all containers (including stopped ones). 
  • docker start: Starts stopped containers. 
  • docker stop: Halts running containers. 
  • docker restart: Restarts containers. 
  • docker login: Logs into a Docker registry. 
  • docker logout: Logs out from a Docker registry. 
  • docker rm: Removes a container. 
  • docker rmi: Removes an image. 
  • docker build: Creates an image from a Dockerfile. 
  • docker-compose: Manages multi-container Docker apps. 
  • docker version: Shows Docker version info. 
  • docker kill: Forces a container to stop. 
  • docker pull: Fetches an image from a registry. 
  • docker push: Sends an image to a registry. 
  • docker export: Saves a container’s filesystem as a tar. 
  • docker volume: Manages data volumes. 
  • docker exec: Runs a command in a running container. 
  • docker search: Looks for images on Docker Hub. 
  • docker images: Lists available images. 
  • docker attach: Connects to a running container. 
  • docker copy: Copies files/folders between container and host. 
  • docker commit: Creates an image from container changes. 
  • docker history: Shows image history. 
  • docker logs: Displays container logs. 
  • docker network: Manages Docker networks. 

Let’s delve into key Docker commands and their applications. These fundamental Docker commands cater to both novices and seasoned practitioners. 

 

1. docker run:

Docker initiates isolated processes within containers. A container is a self-contained unit running on a local or remote host. Upon executing ‘docker run’, the container process is independent, possessing its distinct file system, network, and process hierarchy separate from the host. 

The fundamental ‘docker run’ command follows this structure: 

Syntax Example: $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] 

Keynote: 

  • OPTIONS: Additional settings for the container, like ports mapping or resource constraints. 
  • IMAGE: The base image for the container. 
  • TAG|@DIGEST: (Optional) Specific version or hash of the image. 
  • COMMAND: (Optional) Initial command to run within the container. 
  • ARG…: (Optional) Arguments to pass to the command. 

Understanding ‘docker run’ enables efficient container deployment and management. 

 

2. docker start:

Resuming halted containers is achieved using ‘docker start’. This command revitalizes one or more previously paused containers, restoring their operational state. 

Syntax example: $ docker start my_container 

Keynote: 

  • my_container: Name or ID of the container to be restarted. 

Employing ‘docker start’ facilitates the reactivation of paused containers, maintaining the workflow without losing prior configurations. 

 

3. docker stop: 

Terminates one or more active containers using ‘docker stop’. This command halts the execution of running containers gracefully. 

Syntax Example: $ docker stop my_container 

Keynote: 

  •  my_container: Name or ID of the container to be stopped. 

By invoking ‘docker stop’, you ensure proper closure of containers, allowing for a controlled exit and resource release. 

 

4. docker build: 

Creating images from Dockerfiles is facilitated by ‘docker build’. This command constructs an image based on instructions within a Dockerfile, streamlining image creation. 

Syntax example: $ docker build [OPTIONS] PATH | URL  

Key Points: 

  • OPTIONS: Additional settings for the build process. 
  • PATH | URL: Path to the Dockerfile directory or URL to a Git repository. 

Leveraging ‘docker build’ enhances image management, enabling efficient customization and deployment. 

Example: Build from a GitHub repository 

$ docker build github.com/creack/docker-firefox 

 

5. docker pull:

Fetching images or repositories from a registry and downloading them is achieved using ‘docker pull’. This command retrieves the specified image, making it available locally for usage. 

Syntax example: $ docker pull [OPTIONS] NAME[:TAG|@DIGEST] 

Key Points: 

  • OPTIONS: Additional settings for the pull operation. 
  • NAME: Name of the image or repository. 
  • TAG | @DIGEST: (Optional) Specific version or hash of the image. 

Example: Pull an image named “dockerimage” 

$ docker pull dockerimage 

Utilizing ‘docker pull’ facilitates efficient image retrieval, ensuring seamless availability for local use. 

 

6. docker export:

Converting a container’s filesystem into a tar archive is achieved through ‘docker export’. This command packages the container’s contents for external use or sharing. 

Syntax examples: 

  • $ docker export [OPTIONS] CONTAINER 
  • $ docker export red_panda > latest.tar 
  • $ docker export --output="latest.tar" red_panda 

Key Points: 

  • OPTIONS: Additional settings for the export operation. 
  • CONTAINER: Name or ID of the container to be exported. 

Using ‘docker export’ simplifies archiving container data for portability or distribution. 

 

7. docker commit:

Generating a new image based on a container’s modifications is facilitated by docker commit. This command captures the altered container state as a reusable image. 

Syntax example: 

  • $ docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] 
  • $ docker commit c3f279d17e0a dev/testimage:version3 

Key Points: 

  • OPTIONS: Additional settings for the commit operation. 
  • CONTAINER: Name or ID of the container to be committed. 
  • REPOSITORY[:TAG]: (Optional) Repository and tag for the new image. 

Employing docker commit streamlines image creation from modified containers, promoting image versioning and customization. 

If you want to know more, then check out the complete list of Docker commands here in the Docker documentation. 

 

Step-by-Step Process of Using Docker on Windows

  • You can run WordPress locally on your laptop by downloading Docker, without having to install Apache, PHP, MySQL etc. The Docker Toolbox creates a containerized version of Linux to run the Docker in a VM.
    • Download Docker Tool Box which will install the Oracle VirtualBox.
    • Install the Extension Pack in the VirtualBox.
    • Type $ docker run hello-world in the terminal to check if your installation has finished correctly.
    • Search for a WordPress image on the Docker Hub to install WordPress locally.
  • Similarly, you can install DokuWiki using dockers.
  • Dockers can be used for testing SDN components

Here are a few samples to get your docker engine up and running.

*All the examples in this article are for installing Docker commands on Windows. You can always run it on a Linux VM.



61 Comments

  • Sreeja

    my containers are not listed…. i use linux…………..what should i do??

  • Ninfa Hemmelgarn

    Your site is so fantastic. I’m going to come back here again

  • Kiara Chueng

    This site is absolutely fabulous!

  • Darwin Bormuth

    Keep up the great work guyz.

  • owenmorris

    Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

  • deepika

    nice post
    thank you

  • wizardhax

    I like this website its a master peace ! Glad I found this on google .

  • Pawan

    Very informational stuff on Docker. Thanks for sharing it.

  • Joan Weisdorfer

    Very good blog you have here but I was curious about if you knew of any message boards that cover the same topics discussed here? I’d really love to be a part of community where I can get comments from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Thanks!

  • Tyson Dykema

    You should take part in a contest for top-of-the-line blogs on the web. I will recommend this site!

  • Grover Paisley

    WONDERFUL Post.thanks for share..more wait .. …

  • Marivel Dreyer

    A formidable share, I simply given this onto a colleague who was doing a bit of evaluation on this. And he the truth is purchased me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to debate this, I feel strongly about it and love reading extra on this topic. If doable, as you develop into expertise, would you thoughts updating your weblog with extra details? It is extremely useful for me. Large thumb up for this blog post!

  • Miguel Kaliszewski

    woh I am happy to find this website through google.

  • Harley Demattia

    Greetings! Very helpful advice within this post! It’s the little changes that produce the greatest changes. Thanks for sharing!

  • Gerardo Bells

    Good post. I learn something more difficult on different blogs everyday. It is going to at all times be stimulating to read content material from different writers and apply a bit of something from their store. I’d desire to make use of some with the content on my blog whether you don’t mind. Natually I’ll give you a hyperlink in your web blog. Thanks for sharing.

  • Jana Couillard

    I got this website from my pal who shared with me regarding this web page and now this time I am browsing this website and reading very informative articles or reviews here.|

  • Frankie Yardley

    I’ve been browsing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before.|

  • Malorie Holton

    Very good info. Lucky me I recently found your website by accident (stumbleupon). I’ve saved as a favorite for later!|

  • Twyla Crotty

    I read this article completely about the comparison of hottest and previous technologies, it’s awesome article.|

  • Susannah Enstad

    WONDERFUL Post.thanks for share..more wait .. …

  • Jim Battistini

    Hey there just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same results.

  • Modesto Pille

    This is a topic that’s close to my heart… Cheers! Exactly where are your contact details though?

  • Yolonda Mao

    some truly great blog posts on this site, thanks for contribution.

  • I have Joomla and a Joomla template(rt_refraction_j15) installed on my website. But i want the same template and css styling, as a basic HTML template, so i don’t have to use Joomla for editing. Is there an easy way to convert the template to basic HTML/CSS template?.

  • Shubham Kumar

    What command should you run to see all running container in docker?

  • Shiwanand

    NICE articulated in simple words
    Thanks!

  • Katy Meszaros

    Greetings! Very useful advice within this post! It is the little changes that will make the greatest changes. Thanks for sharing!

  • Bertram Damasco

    Hey there! I’m at work browsing your blog from my new iphone 3gs! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the fantastic work!

  • Rocco Plumber

    After research a few of the blog posts in your website now, and I actually like your way of blogging. I bookmarked it to my bookmark web site checklist and might be checking again soon. Pls check out my web site as properly and let me know what you think.

  • Preston Cienega

    I quite like reading an article that can make men and women think. Also, thank you for permitting me to comment!

  • Ezequiel Hemesath

    I AGREE

  • Zack Krick

    Does your website have a contact page? I’m having problems locating it but, I’d like to send you an e-mail. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it improve over time.

  • Eli Merna

    There is something in this. Thanks for the advice, how can I thank you?

  • Ruth Kaul

    Hello I am so delighted I found your blog page, I really found you by mistake, while I was browsing on Aol for something else, Regardless I am here now and would just like to say many thanks for a remarkable post and a all round exciting blog (I also love the theme/design), I don’t have time to browse it all at the minute but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the excellent work.

  • Sanjuana Detrick

    Hey! Do you use Twitter? I’d like to follow you if that would be okay. I’m absolutely enjoying your blog and look forward to new posts.

  • Jacqulyn Olberding

    Do you mind if I quote a few of your articles as long as I provide credit and sources back to your website? My blog is in the exact same area of interest as yours and my users would definitely benefit from some of the information you provide here. Please let me know if this okay with you. Cheers!

  • Giovanna Cartmell

    Bravo what a great message

  • January Kadner

    I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to construct my own blog and would like to find out where u got this from. kudos

  • Marisela Mathies

    Greetings from California! I’m bored to tears at work so I decided to check out your site on my iphone during lunch break. I love the knowledge you provide here and can’t wait to take a look when I get home. I’m amazed at how quick your blog loaded on my phone .. I’m not even using WIFI, just 3G .. Anyhow, excellent blog!

  • Nigel Hiefnar

    I love your wordpress design, exactly where would you download it from?

  • Carol Suarez

    A person never realizes all his capabilities while he is chained to the ground. We must take off and conquer the skies.

  • Anas K

    What command should you run to see all running container in docker?

    Docker ps -here will list all running containers
    docker ps -a here will list all running and stoped containers

  • Marlin Leviner

    Your style is very unique compared to other folks I have read stuff from. Many thanks for posting when you’ve got the opportunity, Guess I’ll just bookmark this blog.

  • May Bethurem

    Having read this I believed it was rather informative. I appreciate you spending some time and energy to put this article together. I once again find myself spending a significant amount of time both reading and posting comments. But so what, it was still worth it!

  • Amina Gomzales

    After checking out a few of the articles on your web site, I truly appreciate your technique of blogging. I book marked it to my bookmark site list and will be checking back soon. Please visit my web site too and tell me what you think.

  • Ammie Sloss

    Hey there! I just would like to offer you a big thumbs up for your great information you have got right here on this post. I am returning to your web site for more soon.

  • Shonda Organ

    This page certainly has all the info I wanted concerning this subject and didn’t know who to ask.

  • Cyril Rodriuez

    You’ve made some decent points there. I checked on the net to find out more about the issue and found most people will go along with your views on this website.

  • docker ps -a

    it shows all the running dockers

  • Margarett Bindrup

    I agree with your points, superb post.

  • Hey there, You have done a fantastic job. I’ll definitely digg it
    and personally recommend to my friends. I’m confident
    they will be benefited from this website.

Leave a Reply