docker-compose.yml


Overview

The [docker-compose.yml](/projects/291/68791) file defines and configures Docker services and networks for a local development environment, specifically targeting a backend API service. It leverages Docker Compose to orchestrate container deployment, networking, and runtime parameters, simplifying the process of running the API service locally within isolated and reproducible containers.

This configuration is tailored to work with Traefik as a reverse proxy for routing HTTP requests based on host rules, and it mounts the project source code into the container for live development with nodemon (a Node.js tool that automatically restarts the server on code changes).


Detailed Explanation

Top-Level Structure


Service: api

The `api` service runs the backend API.

Property

Description

image

Specifies the Docker image to use. Here, `unchained-local-node` is a custom/local Node.js image.

`env_file`

Points to the [.env](/projects/291/68960) file to load environment variables into the container.

`labels`

Docker labels used by Traefik for automatic reverse proxy configuration:

  • Enables Traefik for this service.

  • Defines router rule matching HTTP requests to api.base.localhost.

  • Specifies the backend port Traefik should route to (3000).

`working_dir`

Sets the working directory inside the container to `/app/node/coinstacks/base/api`.

`command`

Overrides the default container command to run `yarn nodemon` for hot-reloading during development.

`volumes`

Mounts the local project directory into `/app` inside the container, enabling live code updates.

networks

Connects the container to the `base` Docker network for inter-container communication.

Usage Example (CLI)

docker-compose up api

This command will start the `api` service as defined, mounting the local source code, setting environment variables, and using Traefik for routing.


Network: base

Property

Description

`name`

Sets the network name to `base_default`.

`external`

Marks this network as external, assuming it is already created outside this Compose file.


Important Implementation Details


Interaction with Other System Components


Visual Diagram

flowchart TD
    subgraph Docker Compose
        API[api Service]
        NET[base Network (external)]
    end

    API -- "connects to" --> NET
    API -- "mounts local source\n(../../.. to /app)" --> HostFS[(Host Filesystem)]
    API -- "runs command\n'yarn nodemon'" --> NodeProcess((Node.js Server))
    API -- "Traefik labels\nfor routing" --> Traefik[Traefik Proxy]

    Traefik -- "routes HTTP requests\napi.base.localhost:80 -> API:3000" --> API

Summary

This [docker-compose.yml](/projects/291/68791) file defines a single backend API service running inside a Docker container, optimized for local development with live-reloading. It integrates with Traefik for hostname-based routing and joins an external Docker network for inter-service communication. The configuration promotes rapid development cycles by syncing local code changes directly into the container environment.


If you are setting up or maintaining the local development environment for the backend API, this file is the central orchestrator that ensures the API runs with correct environment variables, routing, and live reload capabilities.