DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Delete Docker Container

A container named kke-container was created by one of the Nautilus project developers on App Server 2. It was solely for testing purposes and now requires deletion. Execute the following task:

Delete the kke-container on App Server 2 in Stratos DC.


Step-by-Step Instructions

1. SSH into Application Server 2

ssh steve@stapp02
Enter fullscreen mode Exit fullscreen mode

(Enter the password when prompted)


2. Switch to root or use sudo

sudo su -
Enter fullscreen mode Exit fullscreen mode

or prefix all commands with sudo


3. Check if the container exists

First, verify the container exists and check its status:

sudo docker ps -a | grep kke-container
Enter fullscreen mode Exit fullscreen mode

Or to see all containers:

sudo docker ps -a
Enter fullscreen mode Exit fullscreen mode

4. Stop the container (if it's running)

If the container is running, stop it first:

sudo docker stop kke-container
Enter fullscreen mode Exit fullscreen mode

5. Delete/Remove the container

sudo docker rm kke-container
Enter fullscreen mode Exit fullscreen mode

6. Verify the container is deleted

sudo docker ps -a | grep kke-container
Enter fullscreen mode Exit fullscreen mode

This should return no results, confirming the container has been removed.


One-Line Command (Force Remove)

If you want to remove it in one command (even if running):

sudo docker rm -f kke-container
Enter fullscreen mode Exit fullscreen mode

The -f flag forces removal of a running container.


Complete Execution

# SSH to App Server 2
ssh steve@stapp02

# Check existing containers
sudo docker ps -a

# Remove the container
sudo docker rm -f kke-container

# Verify deletion
sudo docker ps -a
Enter fullscreen mode Exit fullscreen mode

Important Notes

  • Use docker rm for containers (not docker rmi, which removes images)
  • The -f flag is useful if the container is still running
  • If you get a "No such container" error, the container may already be deleted

Top comments (0)