Skip to content

Define shared Docker network in docker-compose.yml and update frontend to use service name #9

@chigwell

Description

@chigwell

User Story
As a DevOps engineer,
I want to define a shared Docker network in docker-compose.yml
so that backend and frontend services communicate explicitly via a dedicated network,
preventing unpredictable behavior in scaled environments.

Background
The current docker-compose.yml (lines 1-20) relies on Docker’s default bridge network, which:

  • Implicitly connects services without clear dependencies.
  • Risks port conflicts or misrouted traffic when scaling (e.g., multiple backend instances).
  • Lacks explicit network naming, making debugging and service discovery harder.

The frontend’s App.js (line 7) hardcodes http://0.0.0.0:80/ for backend communication, which may fail if the backend’s hostname or port changes in scaled deployments.

Acceptance Criteria

  • Modify docker-compose.yml to:
    • Declare a shared network (e.g., app_network) under networks.
    • Attach both backend and frontend services to this network.
  • Update the frontend’s App.js to use the backend service name (e.g., http://backend/) instead of 0.0.0.0:80.
  • Validate by:
    1. Running docker-compose up and confirming the frontend displays the backend’s "Hello World" message.
    2. Scaling the backend with docker-compose up --scale backend=2 and verifying the frontend can communicate with all instances.
    3. Inspecting the network with docker network inspect [network_name] to confirm both services are attached.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions