docker-compose.yml
Overview
This `docker-compose.yml` file defines and configures Docker services and networks needed to run the Dogecoin API component of the project in a local development environment. Specifically, it sets up a single service named `api` that runs the Dogecoin API server inside a Docker container, leveraging an image called `unchained-local-node`. The configuration includes environment variables, networking, service labels for Traefik reverse proxy integration, volume mounts for live code synchronization, and command overrides to use `yarn nodemon` for hot-reloading during development.
This file is essential for containerizing the Dogecoin API service, enabling consistent and isolated development environments, and seamless integration with other services and the local Traefik proxy.
Detailed Explanation
Services Section
api service
Purpose: Runs the Dogecoin API server in a containerized Node.js environment.
Configuration Parameters:
Key
Description
`image`
Specifies the Docker image to use: `unchained-local-node`. This image contains the Node.js runtime and project dependencies.
`env_file`
Points to a `.env` file to load environment variables into the container.
`labels`
Metadata for the Traefik reverse proxy:
traefik.enable=true: Enables Traefik for this container.
traefik.http.routers.dogecoin-api.rule=Host(api.dogecoin.localhost): Defines routing based on hostname.
traefik.http.services.dogecoin-api.loadbalancer.server.port=3000: Exposes port 3000 internally for Traefik.
`working_dir`
Sets the working directory inside the container to `/app/node/coinstacks/dogecoin/api`, where the API source code resides.
`command`
Overrides the container's default command to `yarn nodemon`, enabling automatic restart on code changes.
`volumes`
Mounts the local project directory `../../..` into `/app` inside the container, allowing live code editing.
`networks`
Connects this service to the external Docker network `dogecoin`.
Usage Example:
To start the Dogecoin API service, run:
docker-compose up apiThis command will launch the container, start the API with live reload support, and make it accessible through Traefik via
http://api.dogecoin.localhost.
Networks Section
dogecoin network
Purpose: Defines a Docker network named
dogecoin_defaultwhich is external to this compose file. This external network enables communication between this service and other related services or containers that are part of the Dogecoin subsystem or project.Key Configuration:
Key
Description
`name`
Specifies the exact Docker network name: `dogecoin_default`.
`external`
Set to `true` indicating Docker Compose will not create this network but expects it to exist.
Usage Note:
Make sure the external network
dogecoin_defaultexists before starting this service. You can create it with:docker network create dogecoin_default
Important Implementation Details
Traefik Integration: The use of Traefik labels configures automatic routing and load balancing for the API service, allowing clean domain-based routing on the local machine without manual port mapping.
Volume Mounting for Development: By mounting the local project directory into the container, developers can modify code locally and have changes reflected immediately inside the container, especially when combined with
nodemonfor hot reloading.Working Directory: The
working_dirpoints to a sub-path where the Dogecoin API server code lives, ensuring commands run in the correct context.External Network Dependency: This Compose file assumes an existing external network for service connectivity, promoting modular and scalable architecture where multiple services span across different compose files but share common networks.
Interaction with Other Parts of the System
Project Structure: This file specifically targets the Dogecoin API component, which is part of a larger modular system involving multiple cryptocurrencies or components.
Traefik Reverse Proxy: It integrates seamlessly with Traefik, which handles routing, SSL termination (if configured), and load balancing for all local services, enabling unified access via hostnames.
Development Workflow: Works in conjunction with local environment variables defined in
.env, the Node.js environment insideunchained-local-nodeDocker image, and the host file system for source files.Network Sharing: Via the external
dogecoin_defaultnetwork, this service can communicate with other related containers (e.g., database, cache, other microservices) that are part of the Dogecoin stack or overall application infrastructure.
Visual Diagram
Below is a flowchart illustrating the structure and key relationships within this `docker-compose.yml` file:
flowchart TD
subgraph Service["Docker Service: api"]
A[Image: unchained-local-node]
B[Env File: .env]
C[Labels: Traefik config]
D[Working Dir: /app/node/coinstacks/dogecoin/api]
E[Command: yarn nodemon]
F[Volume: ../../..:/app]
G[Network: dogecoin]
end
subgraph Network["Docker Network: dogecoin_default"]
N[External Network]
end
Service --> Network
C -->|Enables Traefik Proxy| Traefik[Traefik Reverse Proxy]
F -->|Live Code Sync| HostFS[Host File System]
Summary
This `docker-compose.yml` file provides a streamlined and focused setup for running the Dogecoin API service in a containerized development environment. It leverages Docker Compose features such as environment files, volume mounting, external networking, and Traefik integration to enable efficient local development, easy routing, and modular architecture compliance within the broader system.