# How to Stop the Memgraph Daemon for Code-Graph-RAG

> Easily stop the Memgraph daemon for your Code-Graph-RAG project. Learn commands to halt Memgraph only or bring down the entire stack for efficient resource management.

- Repository: [Vitali Avagyan/code-graph-rag](https://github.com/vitali87/code-graph-rag)
- Tags: how-to-guide
- Published: 2026-08-11

---

**Use `docker compose -f codebase_rag/docker-compose.yaml stop memgraph` to gracefully halt only the Memgraph container while keeping other services running, or run `docker compose -f codebase_rag/docker-compose.yaml down` to tear down the entire Code-Graph-RAG stack.**

The **Code-Graph-RAG** project by vitali87 orchestrates its graph database layer through Docker Compose, defining the Memgraph daemon as a containerized service in [`codebase_rag/docker-compose.yaml`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/docker-compose.yaml). Properly stopping this service ensures that your graph data persists correctly and system resources are released cleanly.

## Stop Only the Memgraph Service

To halt just the Memgraph daemon without affecting other components like Qdrant or the Lab interface, target the specific service name.

Run the following command from the repository root:

```bash
docker compose -f codebase_rag/docker-compose.yaml stop memgraph

```

*For legacy Docker Compose versions, use `docker-compose` (with a hyphen) instead of `docker compose`.*

This command sends a **SIGTERM** signal to the Memgraph container, allowing the database to shut down gracefully while preserving the container configuration and persistent volumes. Other services defined in the compose file remain active.

## Shut Down the Entire Code-Graph-RAG Stack

When you need to stop all services and free network resources, use the `down` command:

```bash
docker compose -f codebase_rag/docker-compose.yaml down

```

This stops the Memgraph container, removes the associated Docker network, and cleans up ephemeral resources. To also delete the persistent graph data stored in Docker volumes—effectively wiping the database—add the `--volumes` flag:

```bash
docker compose -f codebase_rag/docker-compose.yaml down --volumes

```

## How the Shutdown Works Under the Hood

The Docker Compose configuration in [`codebase_rag/docker-compose.yaml`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/docker-compose.yaml) declares a service named **`memgraph`** that pulls the image `memgraph/memgraph-platform` and exposes ports **7687** (Bolt protocol) and **7444** (web interface). When you execute `docker compose up` (or the repository's `cgr up` helper), Docker creates a container from this image and starts the Memgraph daemon inside it.

According to the source code in [`codebase_rag/stack/constants.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/constants.py), the compose filename is stored as a constant used by CLI utilities, ensuring that commands reference the correct configuration file path. When you invoke `stop`, Docker initiates a graceful shutdown sequence. The `docker compose down` command extends this by removing containers and networks; adding `--volumes` also destroys the on-disk graph data mapped to the container.

The [`codebase_rag/tools/health_checker.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/tools/health_checker.py) module provides health check functionality that queries port 7687 to verify daemon availability, which is useful for confirming that the service has fully terminated after running stop commands.

## Programmatically Stop Memgraph from Python

For automated testing or scripted workflows, you can invoke the Docker Compose command via Python's `subprocess` module. The repository's test suite uses this approach in fixtures to manage container lifecycles:

```python
import subprocess

def stop_memgraph():
    """Stop only the Memgraph service defined in the project's Docker Compose."""
    subprocess.run(
        ["docker", "compose", "-f", "codebase_rag/docker-compose.yaml", "stop", "memgraph"],
        check=True,
    )

```

This method executes the same CLI command with the same arguments, ensuring consistency between manual and automated operations.

## Summary

- **Targeted shutdown**: Use `docker compose -f codebase_rag/docker-compose.yaml stop memgraph` to halt only the graph database while preserving other Code-Graph-RAG services.
- **Full stack teardown**: Use `docker compose -f codebase_rag/docker-compose.yaml down` to stop all containers and remove networks; add `--volumes` to delete persistent graph data.
- **Configuration source**: The service is defined in [`codebase_rag/docker-compose.yaml`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/docker-compose.yaml) using the `memgraph/memgraph-platform` image with ports 7687 and 7444 exposed.
- **Automation support**: Python scripts can trigger shutdowns via `subprocess.run()` using the same command structure found in the repository's test fixtures.

## Frequently Asked Questions

### Does stopping Memgraph delete my graph data?

No. Using `docker compose stop` or `docker compose down` without the `--volumes` flag preserves your data in Docker volumes. However, running `docker compose -f codebase_rag/docker-compose.yaml down --volumes` will permanently delete the persistent storage associated with the Memgraph container, wiping all graph data.

### What is the difference between `docker compose stop` and `down`?

The `stop` command halts running containers but leaves the container definitions, networks, and volumes intact, allowing for quick restarts with `docker compose start`. The `down` command stops containers and additionally removes the containers, networks, and (optionally) volumes, requiring a fresh `up` command to recreate the entire stack.

### How do I verify that Memgraph has stopped successfully?

You can check running containers with `docker ps` to confirm the Memgraph container is no longer listed. Alternatively, the repository's [`codebase_rag/tools/health_checker.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/tools/health_checker.py) module implements health checks against port 7687; if these checks fail to connect, the daemon has stopped. The `cgr status` command also utilizes this health checker to report service availability.

### Can I restart Memgraph without rebuilding the container?

Yes. If you used `docker compose stop`, simply run `docker compose -f codebase_rag/docker-compose.yaml start memgraph` to resume the existing container with data intact. If you used `down` without the `--volumes` flag, run `docker compose up` again; this recreates the container but mounts the existing persistent volume, preserving your graph data.