Remove specific service

How to remove a specific service in docker

Docker Service Complete Removal Guide

This guide documents the complete removal of any service from a Docker environment, including all containers, images, volumes, networks, and configuration files.

Prerequisites

  • Docker installed and running

  • Administrative privileges (sudo access)

  • Some service installation present on the system

Step-by-Step Removal Process

1. Check Current Docker Status

First, identify all SERVICE_NAME-related Docker resources:

# Check for SERVICE_NAME containers (running and stopped)
docker ps -a | grep -i SERVICE_NAME

# Check for SERVICE_NAME images
docker images | grep -i SERVICE_NAME

# Check for SERVICE_NAME volumes
docker volume ls | grep -i SERVICE_NAME

# Check for SERVICE_NAME networks
docker network ls | grep -i SERVICE_NAME

Expected Output: This will show all SERVICE_NAME containers, images, volumes, and networks that need to be removed.

2. Stop Running Containers

Stop all running SERVICE_NAME containers:

docker stop SERVICE_NAME-SERVICE_NAME SERVICE_NAME-postgres

What this does: Gracefully stops the SERVICE_NAME application and PostgreSQL database containers.

3. Remove Containers

Remove the stopped containers:

docker rm SERVICE_NAME-SERVICE_NAME SERVICE_NAME-postgres

What this does: Permanently removes the container instances, freeing up their names for future use.

4. Remove Docker Images

Remove the SERVICE_NAME Docker images to free up disk space:

docker rmi ghcr.io/SERVICE_NAMEnban/SERVICE_NAME:2.0.0-rc.3

What this does: Removes the SERVICE_NAME image, freeing up disk space. You'll need to re-download if you want to reinstall the service later.

5. Remove Docker Volumes

Remove all SERVICE_NAME-related volumes (⚠️ This deletes all data):

docker volume rm SERVICE_NAME_attachments SERVICE_NAME_background-images SERVICE_NAME_db-data SERVICE_NAME_favicons SERVICE_NAME_user-avatars

What this does: Permanently deletes all SERVICE_NAME data including:

  • User attachments

  • Background images

  • Database data

  • Favicons

  • User avatars

6. Remove Docker Networks

Remove the custom SERVICE_NAME network:

docker network rm SERVICE_NAME_default

What this does: Removes the custom Docker network created for SERVICE_NAME containers.

7. Remove Configuration Directory

Remove the SERVICE_NAME configuration directory:

sudo rm -rf /opt/SERVICE_NAME

What this does: Removes the configuration directory containing docker-compose.yml and any other configuration files.

8. Verification

Verify complete removal:

# Verify no SERVICE_NAME containers remain
docker ps -a | grep -i SERVICE_NAME

# Verify no SERVICE_NAME images remain
docker images | grep -i SERVICE_NAME

# Verify no SERVICE_NAME volumes remain
docker volume ls | grep -i SERVICE_NAME

# Verify no SERVICE_NAME networks remain
docker network ls | grep -i SERVICE_NAME

# Verify configuration directory is gone
ls -la /opt/SERVICE_NAME 2>/dev/null || echo "Directory /opt/SERVICE_NAME does not exist"

# Check that ports are free
lsof -i :3000 -i :3001 2>/dev/null || echo "Ports 3000 and 3001 are free"

Expected Result: All commands should return empty results or confirmation messages, indicating complete removal.

What Gets Removed

Component
Description
Impact

Containers

Running application instances

Stops all SERVICE_NAME services

Images

Docker images

Frees disk space, requires re-download for reinstall

Volumes

Persistent data storage

⚠️ Permanently deletes all user data

Networks

Custom Docker networks

Cleans up network configuration

Config Files

/SERVICE_NAME directory

Removes docker-compose.yml and settings

Important Notes

⚠️ Data Loss Warning: Step 5 (removing volumes) permanently deletes all the service data including user and database content. This action is irreversible.

Complete Removal: After following this guide, no traces of the service will remain on your system.

🔄 Reinstallation: To reinstall the service later, you'll need to start from scratch as all configuration and data will be gone.

Troubleshooting

If containers won't stop:

docker kill SERVICE_NAME-SERVICE_NAME SERVICE_NAME-postgres

If volumes won't delete (in use):

docker system prune -f
docker volume prune -f

If permission denied on config directory:

sudo chown -R $(whoami) /opt/SERVICE_NAME
rm -rf /SERVICE_FOLDER

Last updated