docker-compose.yml
Overview
The [docker-compose.yml](/projects/291/68791) file defines a multi-container Docker application configuration specifically tailored for running a Solana blockchain API service in a local development environment. It describes how to launch the `api` service container using a pre-built image, configure its runtime environment, networking, and volume mounts, and integrates it with Traefik for HTTP routing.
This file enables developers to quickly start the Solana API backend with all required dependencies and environment settings, facilitating rapid development and testing without manual container orchestration commands.
File Structure and Components
The file is divided into two main sections:
services: Defines the containers that will be run.
networks: Specifies Docker networks used for container communication.
Services
api
The `api` service represents the backend API server for Solana blockchain interactions.
Configuration Key | Description |
|---|---|
`image: unchained-local-node` | Specifies the Docker image to use for this service. Presumably, this image contains the Node.js runtime and the Solana API application code. |
`env_file: .env` | Loads environment variables from a `.env` file, allowing configuration parameters to be injected at runtime. |
`labels` | Defines Traefik-specific labels to configure HTTP routing for the container. |
Sets the working directory inside the container where commands will be executed. | |
Runs the `yarn nodemon` command to start the Node.js server with live reload capability. | |
`volumes` | Mounts the host directory `../../..` into `/app` inside the container, enabling code changes to reflect immediately. |
`networks` | Connects the service to the `solana` Docker network for inter-container communication. |
Detailed Explanation of labels
traefik.enable=true: Enables Traefik proxying on this container.traefik.http.routers.solana-api.rule=Host(api.solana.localhost): Defines a routing rule based on the hostname to route traffic to this container.traefik.http.services.solana-api.loadbalancer.server.port=3000: Specifies the port Traefik should forward requests to inside the container.
Usage Example
To run this service:
docker-compose up api
This command will:
Pull or build the
unchained-local-nodeimage if not present.Start the API container with live code reload.
Make the Solana API available at
http://api.solana.localhostvia Traefik.
Networks
solana
The `solana` network is an externally defined Docker network (not created by this compose file) named `solana_default`. It is used to connect the `api` service to other containers or services participating in the Solana-related stack, enabling seamless communication.
networks:
solana:
name: solana_default
external: true
This setup assumes that a network named `solana_default` already exists, possibly created by other Docker Compose configurations or manually.
Important Implementation Details
Volume Mounting: The host directory is mounted inside the container at
/appallowing real-time code updates without rebuilding the image.Traefik Integration: The use of Traefik labels facilitates automatic service discovery and HTTP routing, abstracting the complexity of manual proxy configuration.
Working Directory & Command: Setting
working_dirand runningyarn nodemonensures the container runs from the correct path and supports live reloading during development.
Interaction with Other Parts of the System
The
apiservice is part of a larger modular Solana project, likely connecting with other microservices or blockchain nodes.The external
solana_defaultnetwork allows this container to communicate with other services in the Solana ecosystem.Traefik acts as the reverse proxy/load balancer routing external HTTP requests (e.g., from
api.solana.localhost) to this service.The
.envfile referenced can include sensitive or environment-specific configuration like API keys or database URLs, decoupling configuration from code.
Visual Diagram: Service and Network Flow
flowchart TD
subgraph Docker Network: solana_default
API[api Service Container]
end
Host[Developer Machine]
Traefik[Traefik Proxy]
Host -->|HTTP Request to api.solana.localhost| Traefik
Traefik -->|Route traffic port 3000| API
API -->|Uses| EnvFile[.env Configuration]
API -->|Code Mount| HostDir[../../.. mounted to /app]
style API fill:#9fdfbf,stroke:#333,stroke-width:2px
style Traefik fill:#f9d67a,stroke:#333,stroke-width:2px
style HostDir fill:#a2c4c9,stroke:#333,stroke-width:2px
style EnvFile fill:#d3d3d3,stroke:#333,stroke-width:2px
Summary
The [docker-compose.yml](/projects/291/68791) file efficiently orchestrates a containerized Solana API development environment by:
Using a dedicated Node.js image for the API service.
Incorporating environment variables from a
.envfile for flexible configuration.Enabling Traefik-powered routing with hostname-based rules.
Mounting source code from the host to support live development.
Joining an external Docker network for inter-service communication.
This setup accelerates local development by reducing manual setup and providing a seamless developer experience with hot-reloading and easy HTTP routing.
If you need further details on integrating this compose file with other services or extending it for production, please let me know!