---
title: "API Server"
description: "This document describes the setup for running the Embedchain API server using Docker Compose. The provided docker-compose.yml file defines a single service, backend, which encapsulates the API serv..."
last_updated: "2026-05-07T04:45:15.056148+00:00"
canonical_url: "https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/section-6/api-server"
---

<details>
<summary>Relevant source files</summary>

The following files were used as context for generating this wiki page:

- [embedchain/examples/api_server/docker-compose.yml](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml)
</details>

This document describes the setup for running the Embedchain API server using Docker Compose. The provided `docker-compose.yml` file defines a single service, `backend`, which encapsulates the API server application. This setup facilitates easy deployment and management of the API server within a containerized environment, ensuring consistent operation across different development and production stages.

The primary purpose of this configuration is to build the API server's Docker image, manage its environment variables, map necessary ports for external access, and mount local directories for development or persistent storage.

## API Server Docker Compose Configuration

The `docker-compose.yml` file specifies the configuration for the `backend` service, which represents the Embedchain API server. This service is designed to be built from a local `Dockerfile` and run as a Docker container.

### Service Definition: `backend`

The `backend` service is the core component defined in the Docker Compose file. It outlines how the API server container should be built and executed.

<Callout title="Key Configuration" variant="info">
The `backend` service is configured to build its image from a `Dockerfile` in the current context, use environment variables from `variables.env`, expose port `5000`, and mount the current directory as a volume.
</Callout>

#### Container Naming and Restart Policy

The container for the `backend` service is explicitly named `embedchain_api`. This ensures a predictable and easily identifiable container name. The `restart: unless-stopped` policy dictates that the container will automatically restart unless it is explicitly stopped by the user or Docker daemon.

Sources: [embedchain/examples/api_server/docker-compose.yml:5-6](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L5-L6)

#### Image Build Context

The Docker image for the `backend` service is built from a `Dockerfile` located in the current directory (`.`). This allows for custom build instructions specific to the API server application.

Sources: [embedchain/examples/api_server/docker-compose.yml:7-9](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L7-L9)

#### Environment Variables

Environment variables required by the API server are loaded from a file named `variables.env`. This approach keeps sensitive or configuration-specific variables separate from the `docker-compose.yml` file, promoting better security practices and easier management.

Sources: [embedchain/examples/api_server/docker-compose.yml:10-11](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L10-L11)

#### Port Mapping

The API server running inside the container listens on port `5000`. This port is mapped to port `5000` on the host machine, making the API server accessible from outside the Docker container at `http://localhost:5000` (or the host's IP address).

Sources: [embedchain/examples/api_server/docker-compose.yml:12-13](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L12-L13)

#### Volume Mounting

A volume is mounted from the current directory (`.`) on the host machine to `/usr/src/api` inside the container. This is particularly useful for development, allowing changes made to the source code on the host to be reflected inside the container without rebuilding the image, often enabling hot-reloading features of the application.

Sources: [embedchain/examples/api_server/docker-compose.yml:14-15](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L14-L15)

### API Server Deployment Flow

The following diagram illustrates the steps involved in deploying the Embedchain API server using the provided `docker-compose.yml` file.



### Configuration Summary

The table below summarizes the key configuration parameters for the `backend` service as defined in the `docker-compose.yml`.

| Parameter       | Value                      | Description                                                              | Source                                                              |
| :-------------- | :------------------------- | :----------------------------------------------------------------------- | :------------------------------------------------------------------ |
| `container_name`| `embedchain_api`           | The name assigned to the Docker container.                               | [docker-compose.yml:5](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L5) |
| `restart`       | `unless-stopped`           | Policy for restarting the container.                                     | [docker-compose.yml:6](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L6) |
| `build.context` | `.`                        | Directory where the `Dockerfile` is located.                             | [docker-compose.yml:8](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L8) |
| `build.dockerfile`| `Dockerfile`             | The name of the Dockerfile to use.                                       | [docker-compose.yml:9](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L9) |
| `env_file`      | `variables.env`            | File containing environment variables.                                   | [docker-compose.yml:11](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L11) |
| `ports`         | `5000:5000`                | Maps host port 5000 to container port 5000.                              | [docker-compose.yml:13](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L13) |
| `volumes`       | `.:/usr/src/api`           | Mounts the current directory to `/usr/src/api` inside the container.     | [docker-compose.yml:15](https://github.com/blade47/mem0/blob/main/embedchain/examples/api_server/docker-compose.yml#L15) |

### Interaction with External Components

The API server, once running, is designed to interact with external clients via the exposed port 5000. The `variables.env` file would typically contain configurations for databases, external APIs, or other services that the API server depends on.

```mermaid
sequenceDiagram
    actor Client
    participant HostMachine
    participant DockerCompose
    participant EmbedchainAPI as "embedchain_api<br>(Container)"

    Client->>HostMachine: HTTP Request (e.g., GET /status)
    HostMachine->>HostMachine: Port 5000 mapped to container
    HostMachine->>EmbedchainAPI: Forward Request
    EmbedchainAPI->>EmbedchainAPI: Process Request
    EmbedchainAPI-->>HostMachine: HTTP Response
    HostMachine-->>Client: Forward Response
```

## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/llms.txt) for all pages in this wiki.
