I'm running hello world
docker container in a shell script:
#!/bin/bash
sudo docker run hello-world
I'm doing this to verify if the installation of docker was correct. After this I would like to remove this container again. But as I don't know the ID of this new container I can't remove it:
sudo docker rm hello-world
... is failing.
If you haven't already, open a terminal and ssh into the machine where you run your manager node. For example, the tutorial uses a machine named manager1 . Run docker service rm helloworld to remove the helloworld service. Even though the service no longer exists, the task containers take a few seconds to clean up.
To remove the image, you first need to list all the images to get the Image IDs, Image name and other details. By running simple command docker images -a or docker images . After that you make sure which image want to remove, to do that executing this simple command docker rmi <your-image-id> .
In the docs of docker: Explore the Application it's described how you can do this.
When you docker run hello-world
, the container gets created with a random name that you can check with the following command:
docker container ls --all
Under the NAMES
column of the output of the command you can check the generated name (you can see below on my example image. peaceful_morse in my case).
Then you can use this name as a parameter when you call the docker remove command:
docker rm peaceful_morse
Image with all the steps:
Give the container a name:
sudo docker run --name hello-world-container hello-world
Then you can remove it by name:
sudo docker rm hello-world-container
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With