> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.sqd.dev/feedback

```json
{
  "path": "/en/sdk/squid-sdk/resources/self-hosting",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# Self-hosting

> Self-host Squid SDK indexers locally or on-premises with Docker — single-image setup for processor and GraphQL server with Postgres backing storage.

<Tip>
  Many tips from our [best practices guide](/en/cloud/resources/best-practices) apply to self-hosted squids, too. Check it out if you intend to use your squid in production.
</Tip>

To deploy a squid locally or on-premises, use the following Dockerfile template to build a single image for both `api` and `processor` services:

```dockerfile title="Dockerfile" theme={"system"}
FROM node:20-alpine AS node
FROM node AS node-with-gyp
FROM node-with-gyp AS builder
WORKDIR /squid
ADD package.json .
ADD package-lock.json .
# remove if needed
ADD assets assets
# remove if needed
ADD db db
# remove if needed
ADD schema.graphql .
RUN npm ci
ADD tsconfig.json .
ADD src src
RUN npm run build
FROM node-with-gyp AS deps
WORKDIR /squid
ADD package.json .
ADD package-lock.json .
RUN npm ci --production
FROM node AS squid
WORKDIR /squid
COPY --from=deps /squid/package.json .
COPY --from=deps /squid/package-lock.json .
COPY --from=deps /squid/node_modules node_modules
COPY --from=builder /squid/lib lib
# remove if no assets folder
COPY --from=builder /squid/assets assets
# remove if no db folder
COPY --from=builder /squid/db db
# remove if no schema.graphql is in the root
COPY --from=builder /squid/schema.graphql schema.graphql
# remove if no commands.json is in the root
ADD commands.json .
RUN echo -e "loglevel=silent\\nupdate-notifier=false" > /squid/.npmrc
RUN npm i -g @subsquid/commands && mv $(which squid-commands) /usr/local/bin/sqd
ENV PROCESSOR_PROMETHEUS_PORT 3000
```

Then build an image with

```bash theme={"system"}
docker buildx build . -t my-squid
```

or with

```bash theme={"system"}
docker build . -t my-squid
```

if you're using an older Docker version.

## Sample compose file

Once can the run the squid services with the freshly built image. Here is a sample `docker-compose` file:

```yaml theme={"system"}
services:
  db:
    image: postgres:15
    environment:
      POSTGRES_DB: squid
      POSTGRES_PASSWORD: postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready", "-d", "squid"]
      interval: 5s
      timeout: 5s
      retries: 5
    # Uncomment for logging all SQL statements
    # command: ["postgres", "-c", "log_statement=all"]
  api:
    image: my-squid
    environment:
      - DB_NAME=squid
      - DB_PORT=5432
      - DB_HOST=db
      - DB_PASS=postgres
      - GQL_PORT=4350
    ports:
      # GraphQL endpoint at port 4350
      - "4350:4350"
    command: ["sqd", "serve:prod"]
    depends_on:
      db:
        condition: service_healthy
  processor:
    image: my-squid
    environment:
      - DB_NAME=squid
      - DB_PORT=5432
      - DB_HOST=db
      - DB_PASS=postgres
      # any other variables that your squid processor may be using
    ports:
      # prometheus metrics exposed at port 3000
      - "3000:3000"
    command: ["sqd", "process:prod"]
    depends_on:
      db:
        condition: service_healthy
```

Note that `sqd serve:prod` and `sqd process:prod` commands are defined in the [`commands.json` file](/en/sdk/squid-sdk/squid-cli/commands-json).
