docker-compose.yml


Overview

The [docker-compose.yml](/projects/291/68791) file defines and configures a multi-container Docker application focused on running an Ethereum API service locally. It specifies the services, networks, volumes, and environment settings necessary to launch the application in a Docker environment using Docker Compose.

In this particular file, the configuration is minimal and centers around a single service named `api`, which runs an Ethereum-related API server inside a container. The service is set up to integrate with Traefik, a modern reverse proxy and load balancer, for routing HTTP requests based on host rules.

This setup facilitates local development and testing by mounting the source code into the container and enabling hot-reloading through `nodemon`.


Detailed Explanation

Top-level Keys


Service: api

This is the main service defined in this file. It runs the Ethereum API server.

Property

Description

`image`

Specifies the Docker image to use. Here, `unchained-local-node` is a custom image, presumably pre-built for the Ethereum node environment.

`env_file`

Loads environment variables from a file named `.env` in the local directory. This file typically contains sensitive or environment-specific configurations.

`labels`

Add metadata to the container used by Traefik for routing HTTP traffic to this service. These labels:

  • Enable Traefik (`traefik.enable=true`)

  • Define router rule to route requests for `api.ethereum.localhost` host (`traefik.http.routers.ethereum-api.rule`)

  • Define the internal port Traefik should proxy (`traefik.http.services.ethereum-api.loadbalancer.server.port=3000`)

`working_dir`

Sets the working directory inside the container to `/app/node/coinstacks/ethereum/api`. This directory likely contains the API source code.

`command`

Overrides the default container start command to run `yarn nodemon`, which starts the API with automatic restarts on file changes, aiding development.

`volumes`

Mounts the host directory three levels up (`../../..`) into `/app` inside the container, allowing live code changes without rebuilding the container.

networks

Connects this service to the `ethereum` network, enabling communication with other containers on this network.


Network: ethereum

Property

Description

`name`

Explicitly names the Docker network `ethereum_default`.

`external`

Indicates this network is external and managed outside this Compose file. It must already exist.


Usage Example

To launch the services defined in this file, you would typically run:

docker-compose up

This command will:

You should be able to access the Ethereum API at:

http://api.ethereum.localhost

(provided Traefik is properly configured and running on your host machine).


Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Diagram: Service Workflow and Relationships

flowchart TB
    subgraph Docker Compose Application
        direction TB
        API[API Service Container]
        EnvFile[.env File]
        SourceCode[Host Source Code (../../..)]
        Traefik[Traefik Reverse Proxy]
        EthereumNetwork[(ethereum_default Network)]
    end

    SourceCode -->|Volume Mount| API
    EnvFile -->|Environment Variables| API
    API -->|Connected to| EthereumNetwork
    API -->|Labels for Routing| Traefik
    Traefik -->|Routes HTTP requests| API

    click SourceCode href "file:///../../.." "Host Source Code Directory"
    click EnvFile href "file:///.env" ".env Environment File"

Summary

This [docker-compose.yml](/projects/291/68791) file sets up a local development container for an Ethereum API service. It leverages Docker Compose to define the service container, environment variables, network connectivity, and integration with Traefik for HTTP routing. The configuration optimizes for developer productivity with hot-reloading and source code mounting and fits into a broader Ethereum development ecosystem by connecting to an external Docker network.


**End of documentation**