Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Containers » Stopping, Removing and Naming Docker Container
  • windows 10 technical preview windows 10 logo microsoft 97543 1920x1080
    Disable the sleep mode in Windows to never turn off the display Windows
  • Amazon EC2 and S3
    How to sync S3 Bucket with an EC2 instance AWS/Azure/OpenShift
  • Screenshot 2022 04 02 at 22.59.54
    How to fix importing the project failed: Project namespace path can contain only letters, digits, etc Version Control System
  • banner
    How to hide Folders and Files from Search Results in Windows Windows
  • VHDX resizing and veeam back
    Hyper V Disk allocation: Why Veeam reports full size after Shrinking Windows Server
  • 1237968 3d79
    How to perform sysprep in Windows Windows
  • Fix Windows Security Blank Screen Issue
    How to Fix Windows Security Blank Screen Issue Network | Monitoring
  • domain14 1
    How To Configure a Domain Password Policy Windows

Stopping, Removing and Naming Docker Container

Posted on 24/10/202128/09/2023 Imoh Etuk By Imoh Etuk No Comments on Stopping, Removing and Naming Docker Container
How-to-stop-remove-and-manage-docker-container

Containers provide a lightweight feature for your applications to run in an isolated environment. Furthermore, it packages your application code and dependencies together and runs them at the application layer. Multiple containers can run on the same machine and share the same OS kernel with other containers when compared to Virtual Machines which requires a full copy of an Operating System before it can run Here’s all you need to know about stopping, removing and naming docker containers. For details on Container VS Operating System, refer to the related post on how to Pull your first Nginx Container Image from Docker Hub and deploy it to your local machine. To learn further about Docker, please see other related posts on Azure DevOps and GitHub integration for Docker and Kubernetes deployment, and how to create and deploy a local Registry Server with Docker Image.

You can also refer to my previous articles on how to Create an App Service Plan with Continuous Deployment to deploy a .NET Application from GitHub.

I have my container created already and hosted in my local environment. In addition, to get along with this write-up, you need to:

  • install Docker Desktop Application on your Windows 10 Operating System. Afterward, click here to download
  • enable the Hyper-V on your System. Follow these steps to enable it.
  • download and install Git Bash Terminal. Download it here

After you’ve prepared and set your environment, and have your container up and running. Then, it’s time to get to the business of the day.

We have a container named dazzling_kapitsa running on TCP Port 3000 localhost and mapped to the TCP Port 80 in the NGINX container. This write-up aims to show you the quickest ways to stop, remove and name Containers in your localhost machine.

Running-container-screen-1
Running Container Screen

Stopping a Docker Running Container

Container being a running instance of an image and they are connected in some ways, that’s why when you run the command <docker stop>  and pass the name or the Id of the container you wish to stop, the container, as well as the Docker Image, will automatically stop running.

For instance,  in my case the name of my container is dazzling_kapitsa , so what I will just do to stop it is to run the command <docker stop> in my terminal followed by the container Id <b004138ff9b4> or  <dazzling_kapitsa> and hit the Enter key. To do this, I will run the <docker ps> command so I will be able to locate the container Id or name of the running container. Refer to the screenshot below for clarity:

stopped-container-in-terminal-1
Stopping Docker Container in Terminal

Now we have successfully stopped our Container. Thus, if we refresh the web browser, it will report the error showing on the screenshot below:

Stopped-container-screenppt
Stopped Container Browser and Docker Desktop Environment Screen

Moving forward, an interesting thing is we just stopped the Container, but we haven’t removed it, so the container is still available to start. So, to start the Container again, simply grab the name or the Id and press enter to get it up and running again.

To see a list of running Containers, run docker ps. As you can see there is no running container at the moment. See the screenshot below:

No-Running-Container
No Running Container

To explore the docker ps command more, run docker ps –help

List containers

Options:

  • -a, –all:   Show all containers (default shows just running)
  • -f, –filter filter:   Filter output based on conditions provided u
    • –format string:     Pretty-print containers using a Go template
  • -n, –last int:  Show n last created containers (includes all states) (default -1)
  • -l, –latest:    Show the latest created container (includes all states)
  • –no-trunc:    Don’t truncate output
  • -q, –quiet:    Only display container IDs
  • -s, –size:             Display total file sizes

Now, let’s go ahead and use docker ps –a  to see the names of all the Containers in our runtime environment.

Names-of-all-the-containers-nc
Names of all Containers
Note! Each time we stopped and restarted a Container, it changes the name and the Id. We never reuse those details. we get a brand new container name and Id.

How do we delete a container? This takes us to another point below:

Removing/Deleting a Docker Container from Runtime Environment

To delete a container what you need to do is to run, docker delete followed by the container Id or name. To do so run the command below:

docker rm <container Id or Name>
Number-of-containers-left
Container Deleted

From the screenshot above, notice that we had three containers when we run the docker ps -a command and two containers left after we ran the docker rm <containerId> command. For clarity, let’s execute the -aq command above. By running docker ps -aq. This gives us the Id only as shown in the screenshot below:

aq-command
Dash (-) aq command

The -aq command, runs the container in a quiet mode by displaying only the IDs.

Now, what if we want to remove all the Containers? Yes, let’s remove all the containers by running:

docker rm $(docker ps -aq)
All-containers-removed
All Containers Removed

Bear in mind that if you have a running container, the command above won’t work.

Now let’s go ahead and pull a container and run it then attempt to use the docker rm $(docker ps -aq) command again. Furthermore, run docker ps command to see the running Container and attempt to remove it again with the docker rm $(docker ps -aq) command.

From the screenshot below, we can see the there is an error message that the Container cannot be deleted because it is still in a running mode which means you need to stop the Container first before the docker rm $(docker ps -aq) command can work.

Running-Container12.PNG
Running Container cannot be deleted

What if you want to force delete the Container even if it’s in the running mode? That’s if you say all I want is to delete the Container I really don’t care if it’s running or not 😊😊. Then, all you need to do is to just run:

docker rm –f $(docker ps –aq)

Running the above command will remove the running Container. Therefore, let’s confirm it with the screenshot below:

Force-Rm-Command
Force Rm command

How to Name a Docker Container

While we’ve explored the essentials of stopping and removing containers, let’s delve into naming a docker container.

Namining-Container

You can see from the screenshot above that we have the Container named as fervent_bassi. So usually, this is a random name that’s given to you if you don’t have a name but in reality, when you create your own container, you should give them a name so that you don’t rely on the Id nor the actual random name. So the way that you give a name to a container is simply by using a double dash (–) flag and then the word name.

To get started, let’s go ahead and fore remove the running Container with the docker rm –f $(docker ps –aq) command.

Now, let’s go ahead and run the exact command that we ran to get the Container running i.e. docker run -d -p 3000:80 -p 8080:80 nginx: latest and add the double dash (- -) name flag. To do so, we will run docker docker run –-name techdirectarchive_website -d -p 3000:80 -p 8080:80 nginx:latest

Now if we run docker ps, we can see that the name has changed from fervent_bassi. to techdirectarchive_website. Thus, see the screenshot below:

Container-Name-changed
Container Renamed to techdirectarchive_website

This makes it much easier for you to identify your Container. Trust me, if you always name your Containers because most likely you will be running multiple containers in your live production environment, it will make your life and the work very easy for you.

With this guide, stopping, removing and naming docker containers has become so easy. Thanks for reading👏

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to share on Nextdoor (Opens in new window) Nextdoor
Containers Tags:container, docker

Post navigation

Previous Post: Fix Remote session was disconnected because there are no Remote Desktop License Servers available to provide a license
Next Post: What’s new in Veeam Backup and replication v11?

Related Posts

  • portainer feature
    How to Install Docker Portainer on Linux Containers
  • update Docker desktop
    How to manually update Docker desktop Containers
  • Docker Volumes
    Create and Mount Volume to Docker Container Containers
  • DockerEn
    How to Install and Upgrade Docker Engine From Binaries Containers
  • gitlabcomplete
    Install Docker Desktop and register GitLab-Runner with Docker-windows executor Containers
  • Docker OSTypelinux
    The executor requires OSType=windows, but Docker Engine supports only OSType=linux Containers

More Related Articles

portainer feature How to Install Docker Portainer on Linux Containers
update Docker desktop How to manually update Docker desktop Containers
Docker Volumes Create and Mount Volume to Docker Container Containers
DockerEn How to Install and Upgrade Docker Engine From Binaries Containers
gitlabcomplete Install Docker Desktop and register GitLab-Runner with Docker-windows executor Containers
Docker OSTypelinux The executor requires OSType=windows, but Docker Engine supports only OSType=linux Containers

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a
 
  • windows 10 technical preview windows 10 logo microsoft 97543 1920x1080
    Disable the sleep mode in Windows to never turn off the display Windows
  • Amazon EC2 and S3
    How to sync S3 Bucket with an EC2 instance AWS/Azure/OpenShift
  • Screenshot 2022 04 02 at 22.59.54
    How to fix importing the project failed: Project namespace path can contain only letters, digits, etc Version Control System
  • banner
    How to hide Folders and Files from Search Results in Windows Windows
  • VHDX resizing and veeam back
    Hyper V Disk allocation: Why Veeam reports full size after Shrinking Windows Server
  • 1237968 3d79
    How to perform sysprep in Windows Windows
  • Fix Windows Security Blank Screen Issue
    How to Fix Windows Security Blank Screen Issue Network | Monitoring
  • domain14 1
    How To Configure a Domain Password Policy Windows

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,841 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.