
In this blog post, we will show you how to remove Docker Containers, Images, and Volumes on Ubuntu 24.04. Docker is an open-source platform that helps developers build, deploy, and test applications in isolated containers. The key components of the Docker system are Dockerfile, Docker image, Docker engine, Docker container, Docker Hub, Docker Compose, etc. In this blog post, we will also show you how to install Docker and Docker Compose, create a Docker container, and then remove the container along with its volumes and images.
To learn all this stuff for Docker, you will need around 30 minutes, and every command is straightforward. Let’s get started!
Table of Contents
Prerequisites
- A server running Ubuntu 24.04 OS
- User privileges: root or non-root user with sudo privileges
Update the system
Before we start installing Docker, we need to update the packages to their latest versions. To do that, execute the following command:
sudo apt update -y && sudo apt upgrade -y
Install Docker
Before installing Docker, install the following prerequisites:
sudo apt install ca-certificates curl software-properties-common -y
Then we need to add the Docker GPG key:
sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
Next is to add the Docker repository:
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update the system and install Docker and Docker packages:
sudo apt-get update -y sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Once installed, start and enable the Docker service:
sudo systemctl start docker && sudo systemctl enable docker
Check the status of the Docker service:
sudo systemctl status docker
You should get the following output:
root@host:~# sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
Active: active (running) since Sat 2025-12-13 18:18:26 CST; 13min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 2953 (dockerd)
Tasks: 9
Memory: 25.3M (peak: 26.3M)
CPU: 1.105s
CGroup: /system.slice/docker.service
└─2953 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Everything is installed. Now we can proceed to create a Docker container with all the required data.
Create Docker Container
In this heading, we will show you how to create a Docker container for WordPress and a Docker container for the MySQL database. To do that, create the following file:
sudo nano docker-compose.yaml
And paste the following lines of code:
version: "3.9"
services:
# MySQL Database
db:
image: mysql:5.7
container_name: wp_db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: MySQLRootPassworHere
MYSQL_DATABASE: wpdb
MYSQL_USER: wpuser
MYSQL_PASSWORD: StrongPasswordHere
volumes:
- db_data:/var/lib/mysql
networks:
- wp_network
# WordPress App
wordpress:
image: wordpress:latest
container_name: wp_app
depends_on:
- db
ports:
- "8000:80"
restart: unless-stopped
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wpuser
WORDPRESS_DB_PASSWORD: StrongPasswordHere
WORDPRESS_DB_NAME: wpdb
volumes:
- wp_data:/var/www/html
networks:
- wp_network
volumes:
db_data:
wp_data:
networks:
wp_network:
Save the file and close it. In this example, we have the following:
Image 1: mysql:5.7 Image 2: wordpress:latest Container 1: wp_db Container 2 wp_app Volume 1: db_data Volume 2: wp_data
To start the containers, volumes, images, etc, you need to execute the following command:
docker compose up -d
Once executed, the building process will start:
root@host:~# docker compose up -d [+] up 28/41 ⠴ Image wordpress:latest [⣿⣀⣿⣿⣿⣿⣿⣿⣿⣦⣿⣿⣀⣦⡀⣿⠀⣿⣀⣿⣿⣿⣿⣿⣿⣿] 71.72MB / 272.3MB Pulling 20.6s ⠴ Image mysql:5.7 [⣿⣿⡀⣿⡀⣿⣿⣿⣿⣿⣀⣿⣦] 38.18MB / 148.5MB Pulling
Once done, the output should look like this:
✔ Image wordpress:latest Pulled 105.7s ✔ Image mysql:5.7 Pulled 95.4s ✔ Network root_wp_network Created 0.1s ✔ Volume root_db_data Created 0.0s ✔ Volume root_wp_data Created 0.0s ✔ Container wp_db Created 2.9s ✔ Container wp_app Created
We learned how to create all these. Now, let’s move on to the next step, where we will learn how to remove all these safely.
How to Remove Docker Container
A Docker container is a lightweight, standalone, and executable software package that bundles an application and all its dependencies—code, runtime, system tools, and libraries:
First, we need to list all the containers we have on the system:
docker ps -a
On our system, this is our output:
root@host:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6f113dd8aaa9 wordpress:latest "docker-entrypoint.s…" 32 minutes ago Up 32 minutes 0.0.0.0:8000->80/tcp, [::]:8000->80/tcp wp_app 2423c6914990 mysql:5.7 "docker-entrypoint.s…" 33 minutes ago Up 32 minutes 3306/tcp, 33060/tcp wp_db
To remove a Docker container, we need to use the command with the following syntax:
docker rm
So, to remove the containers we have:
docker rm -f 6f113dd8aaa9 docker rm -f 2423c6914990
How to Remove Docker Volume
A Docker volume is a mechanism for persistently storing and managing data used by Docker containers.
First, we need to list all the volumes we have on the system:
docker volume ls
On our system, this is our output:
root@host:~# docker volume ls DRIVER VOLUME NAME local root_db_data local root_wp_data
To remove a Docker volume, we need to use the command with the following syntax:
Docker volume rm VOLUME_NAME
So, to remove the volumes we have:
docker volume rm root_db_data docker volume rm root_wp_data
How to Remove Docker Images
A Docker image is a read-only template that contains all the necessary components – code, runtime, system tools, libraries, and settings – to run an application in a consistent, isolated environment. It is a container image.
First, we need to list all the images we have on the system:
docker image ls
On our system, this is our output:
IMAGE ID DISK USAGE CONTENT SIZE EXTRA mysql:5.7 4bc6bc963e6d 700MB 149MB U wordpress:latest 91eeee906a3e 1.06GB 272MB U
As you can see, every image has its own ID: mysql:5.7 – 4bc6bc963e6d AND wordpress:latest – 91eeee906a3e.
To remove a Docker Image, we need to use the command with the following syntax:
docker rmi IMAGE_ID
So to remove the Docker images, we need to use the following commands:
docker rmi 4bc6bc963e6d docker rmi 91eeee906a3e
After execution of all commands, the output should look like this:
root@host:~# docker rm -f 6f113dd8aaa9 6f113dd8aaa9 root@host:~# docker rm -f 2423c6914990 2423c6914990 root@host:~# docker volume rm root_db_data root_db_data root@host:~# docker volume rm root_wp_data root_wp_data root@host:~# docker rmi 4bc6bc963e6d Untagged: mysql:5.7 Deleted: sha256:4bc6bc963e6d8443453676cae56536f4b8156d78bae03c0145cbe47c2aad73bb root@host:~# docker rmi 91eeee906a3e Untagged: wordpress:latest Deleted: sha256:91eeee906a3edacc66550eeca85aff027e13754aba64a98bdb8f9598e8dadeee
Congratulations!
You successfully learned how to install Docker containers and how to remove them, along with the volumes and images on Ubuntu 24.04 OS.
Of course, you do not have to do this on your own if you have difficulties and are not familiar with Linux. All you have to do is sign up for one of our NVMe VPS plans and submit a support ticket. Our admins are available 24/7 and will help you with any aspect of Docker Containers.
If you liked this post about how to remove Docker containers, images, and volumes on Ubuntu 24.04, please share it with your friends on social networks or leave a reply below. Thanks.