A simple way to stop all Docker containers

This is just a quick reminder post to illustrate how to stop all docker containers that are running within a given environment.

As many may already know, you can use the standard Docker stop command to stop a given container.  What if you want to stop all containers within your development environment?  The simple way is to combine Docker commands.

The first command that is useful is to find out what is running.  In this case, the command is:

$ docker pa -a

This command will return a list of all the containers that are present  on the system – running or exited.  What you want to get at this point is the “CONTAINER ID”.  If you add in the -q option, the resulting return set will only display the “CONTAINER ID” that are needed.

bocurtis@MacBook-Pro ~ % docker container stop $(docker ps -a -q)

8389aff2f804
64718fec99f4
b8d66e2701e2
4bd42b951052
b5e1edc7ef1f

The next command that is needed is the stop command.  This command is the command that will actually stop all the containers that is it passed.  Typically this would be one-by-one, but you are trying to stop all of them at one time.  To do this, you simply pass the docker ps command to the  container stop command like so:

$ docker container stop $(docker ps -a -q)

At this point, you can perform a process (ps -a) command and see that everything has been stopped.

Hope the helps and is a quick reference to stopping more than one container.

Enjoy!!!

Please follow and like:
Comments
  • We’re a group of volunteers and starting a new scheme in our community.

    Your web site offered us with valuable info to work on. You’ve done an impressive job and our whole community
    will be thankful to you.

    Also visit my blog post; vpn

  • Hey would you mind sharing which blog platform you’re using?
    I’m going to start my own blog in the near future
    but I’m having a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most blogs and I’m looking for
    something unique. P.S Apologies for being off-topic but I had to ask!

  • Amazing blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple tweeks would
    really make my blog jump out. Please let me know where you got your theme.
    Thanks a lot

  • I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

Leave a Reply

Your email address will not be published. Required fields are marked *

Enquire now

Give us a call or fill in the form below and we will contact you. We endeavor to answer all inquiries within 24 hours on business days.