docker-compose.yml
Overview
The `docker-compose.yml` file defines the configuration for running multi-container Docker applications. This particular file sets up the local development environment for the **Arbitrum Nova API** service within the project. It specifies how the API container should be built, configured, and networked, leveraging Docker Compose to orchestrate the service and its dependencies.
Key functionalities include:
Running the API server inside a Docker container using a predefined image.
Configuring environment variables from an external
.envfile.Setting up Traefik labels for reverse proxy routing and load balancing.
Mounting the local project code into the container for live development.
Connecting the service to an existing Docker network to ensure seamless communication with other components.
Detailed Explanation
Services Section
api
Defines the API service container responsible for running the Arbitrum Nova node API.
Property | Description |
|---|---|
**image** | `unchained-local-node` - Docker image to use for this service. Represents the API runtime. |
**env_file** | `.env` - External file containing environment variables for configuration. |
**labels** | Traefik-specific labels for enabling reverse proxy, routing, and load balancing. |
**working_dir** | [/app/node/coinstacks/arbitrum-nova/api](/projects/291/69281) - Directory inside the container where commands run. |
**command** | `yarn nodemon` - Command to start the API with hot-reloading during development. |
**volumes** | Mounts the project root (`../../..`) into [/app](/projects/291/68852) in the container for live code syncing. |
**networks** | Connects to the `arbitrum-nova` Docker network for inter-service communication. |
Networks Section
Defines the Docker network the API service connects to.
Network Name | Description |
|---|---|
**arbitrum-nova** | External Docker network named `arbitrum-nova_default` shared across project containers. |
Parameters and Usage
This file does not define classes or functions but configures a containerized environment. Below are explanations of important parameters and how to use them in context.
Environment Variables (env_file)
Variables in
.envcontrol runtime configuration such as API keys, ports, or modes.Keeps sensitive data out of the compose file.
Traefik Labels
traefik.enable=true: Enables Traefik reverse proxy for this container.traefik.http.routers.arbitrum-nova-api.rule=Host(\api.arbitrum-nova.localhost`)`: Routes HTTP traffic to this container when the request host matches.traefik.http.services.arbitrum-nova-api.loadbalancer.server.port=3000: Specifies the container port Traefik should route traffic to.
Working Directory & Command
working_dirsets the folder where commands run, important for relative paths.command: yarn nodemon starts the API with Nodemon for automatic restarts on code changes, ideal for development.
Volumes
The volume mounts the local project folder into the container for live syncing, enabling code changes without rebuilding the image.
Networks
Connecting to an external network allows seamless communication with other containers/services like databases or other APIs.
Implementation Details and Algorithms
Hot Reloading with Nodemon: The service uses
nodemonto watch for file changes in the mounted volume and restart the API server automatically, enabling rapid development without manual container restarts.Traefik Integration: Labels are used to configure Traefik dynamically. Traefik acts as a reverse proxy, directing HTTP traffic based on hostnames to the correct container and port, providing load balancing and service discovery.
External Network Usage: By connecting to an existing external network (
arbitrum-nova_default), this service can communicate with other components of the Arbitrum Nova stack while maintaining isolation from unrelated containers.
Interaction with Other System Components
Traefik Proxy: This file assumes a Traefik instance is running and connected to the same Docker network to handle incoming HTTP requests and route them to this API service.
Other Arbitrum Services: The API container shares the
arbitrum-novanetwork with other related services (e.g., blockchain nodes, databases), enabling inter-service communication.Local Development Environment: Developers interact with this container when running the project locally, benefiting from live code updates and unified service management.
Environment Variables: The
.envfile referenced here is part of the broader project configuration, ensuring consistent environment setup across services.
Usage Example
To start the API service locally using this configuration, run:
docker-compose -f docker-compose.yml up
This will:
Launch the
unchained-local-nodecontainer.Apply environment variables from
.env.Connect the container to the
arbitrum-nova_defaultnetwork.Expose the API via Traefik at
http://api.arbitrum-nova.localhost.Enable hot reloading of the API code through Nodemon.
Visual Diagram
The following flowchart illustrates the structure and relationships defined in this `docker-compose.yml` file:
flowchart TD
A[Docker Compose] --> B[API Service]
B -->|Uses| C[unchained-local-node Image]
B -->|Reads| D[.env File]
B -->|Runs| E["yarn nodemon" Command]
B -->|Mounts| F[Local Project Folder]
B -->|Connected to| G[arbitrum-nova Network]
G -->|External Docker Network| H[Other Arbitrum Services]
B -->|Exposed via| I[Traefik Proxy]
I -->|Routes Host api.arbitrum-nova.localhost| B
Summary
The `docker-compose.yml` file is a concise but critical configuration for running the Arbitrum Nova API service inside a Docker container tailored for local development. It integrates environment management, live code syncing, networking, and reverse proxying to provide a seamless developer experience and to ensure the API is accessible and properly routed within the local infrastructure.