PHANTOM
🇮🇳 IN
Skip to content

remove container-names from compose#1141

Open
ChristianKniep wants to merge 4 commits intoMemMachine:mainfrom
ChristianKniep:clean_compose
Open

remove container-names from compose#1141
ChristianKniep wants to merge 4 commits intoMemMachine:mainfrom
ChristianKniep:clean_compose

Conversation

@ChristianKniep
Copy link
Contributor

Purpose of the change

Removing container-name and explicit network from the docker-compose file and the startup script to not box the stack in.

Description

I wanted to start two compose stacks from two branches on my laptop to show the difference of both. The container-name and explicit network name

Fixes/Closes

Fixes #1140

Type of change

[Please delete options that are not relevant.]

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g., code style improvements, linting)
  • Documentation update
  • Project Maintenance (updates to build scripts, CI, etc., that do not affect the main project)
  • Security (improves security without changing functionality)

How Has This Been Tested?

Change the docker exec use in the memmachine-compose script.

Checklist

[Please delete options that are not relevant.]

  • I have signed the commit(s) within this pull request
  • My code follows the style guidelines of this project (See STYLE_GUIDE.md)
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • Confirmed all checks passed
  • Contributor has signed the commit(s)
  • Reviewed the code
  • Run, Tested, and Verified the change(s) work as expected

Screenshots/Gifs

[If applicable, add screenshots or GIFs that show the changes in action. This is especially helpful for API responses. Otherwise, delete this section or type "N/A".]

Further comments

[Add any other relevant information here, such as potential side effects, future considerations, or any specific questions for the reviewer. Otherwise, type "None".]

@ChristianKniep
Copy link
Contributor Author

Two bridges are created with two stacks side-by-side:

$ docker network ls
NETWORK ID     NAME                         DRIVER    SCOPE
48e53306bfef   memmachine-cleanup_default   bridge    local
615a8a558eb7   memmachine-main_default      bridge    local

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes explicit container names and network definitions from the docker-compose.yml file to enable running multiple MemMachine stacks simultaneously on the same machine. Previously, explicit container names (memmachine-postgres, memmachine-neo4j, memmachine-app) and a named network (memmachine-network) prevented users from starting multiple instances, as Docker would report name conflicts. The changes align with Docker Compose best practices by relying on automatic container naming and network creation.

Changes:

  • Removed explicit container_name directives from all services in docker-compose.yml
  • Removed explicit network definitions from docker-compose.yml (Docker Compose will automatically create an isolated network per stack)
  • Updated memmachine-compose.sh to use docker-compose exec with service names instead of docker exec with container names

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
docker-compose.yml Removed container_name fields for postgres, neo4j, and memmachine services; removed explicit network definition and network assignments from all services
memmachine-compose.sh Updated health check commands to use $COMPOSE_CMD exec -T <service_name> instead of docker exec <container_name> for PostgreSQL and Neo4j readiness checks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@sscargal sscargal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good proposal, though it's a less common use case.

This cleanly supports multiple deployments on the same host. Without hard-coded names, we can run: memmachine-prod and memmachine-canary, or memmachine-staging and memmachine-prod simultaneously using Compose project names (-p) and/or different directories.

By default, the project name is derived from the directory name you run Compose in (unless overridden). You can override it with:

  • docker compose -p <project> …
  • COMPOSE_PROJECT_NAME=<project>
  • A .env value for COMPOSE_PROJECT_NAME.

Default container & network names

Without a fixed container_name:, Compose names containers like:

  • <project>-postgres-1
  • <project>-neo4j-1
  • <project>-memmachine-1

When the service is scaled, the suffix increments (…-2, …-3, etc.).

Because the explicit networks: block is removed, Compose will create a single default bridge network:

  • <project>_default

All services are automatically attached to this network.

The compose file declares named volumes (e.g., postgres_data, neo4j_data, etc.). When they don’t have an explicit name: override, Compose will scope them to the project automatically:

  • <project>_postgres_data
  • <project>_neo4j_data
  • <project>_neo4j_logs
  • <project>_memmachine_data
  • <project>_memmachine_logs

Challenges

With this approach, we need to find a way to ensure the service ports don't cause conflicts, which they will in this PR.

Docker Compose only auto-assigns a host port if you omit the host port and publish container ports like this:

ports: ["5432"] (instead of "5432:5432")

Then Docker picks an ephemeral available host port (random-ish), which is:

  • not predictable,
  • not “instance 2 = base+1”,
  • and harder for scripts/docs unless you query it (docker compose port ).

If we want predictable A/B stacks (8080 and 8081, 5432 and 5433, etc.), Compose won’t do that for us. If predictable increments are desired, they must be handled by memmachine-compose.sh (or by user-provided .env files).

  1. User supplies ports per instance (simplest, most transparent)

    • stack A: defaults
    • stack B: POSTGRES_PORT=5433 MEMORY_SERVER_PORT=8081 ...
  2. Script computes ports from an “instance number”

  3. Use random ephemeral ports and print them. This is viable, but less friendly because every run can differ; you must query and display the assigned ports.

TODO

Here are some ideas to further improve this PR

  • Add explicit Compose project naming support to memmachine-compose.sh

    e.g., support --project <project_name>, -p <project_name>, or honoring COMPOSE_PROJECT_NAME (less desirable) so developers/ops can run multiple stacks without relying on “directory name” defaults.

  • Figure out a solution (default and user selectable) for assigning port numbers to the services.

@ChristianKniep
Copy link
Contributor Author

In my case I used different directories (using git worktree). I added an environment variable to define the COMPOSE_PROJECT. In case it's already up I error out:

$ ./memmachine-compose.sh 
[ERROR] Existing Docker Compose project detected with name: memmachinemain - please set a different project name (COMPOSE_PROJECT) or remove existing containers to avoid conflicts.

The ports can already be overwritten using there environment vars

  • POSTGRES_PORT
  • NEO4J_HTTP_PORT
  • NEO4J_HTTPS_PORT
  • NEO4J_PORT
  • MEMORY_SERVER_PORT
  • DOCS_PORT

Thus, when using a single stack nothing will change.
Only difference is that you can not run ./memmachine-compose.sh when the stack is already running (,which would have ran docker-compose up -d again).

@sscargal
Copy link
Contributor

./memmachine-compose.sh is the primary interface, so we'll need to find a solution that keeps existing behavior. The proposed --project,-p option is one idea. We should have a default memmachine project name to maintain the current behavior.

@jgong
Copy link
Contributor

jgong commented Feb 26, 2026

The proposal is a good idea to allow multi-environments on one host, this is great! And thanks to the detailed review comments @sscargal @ChristianKniep , i understand how it behaves better after the change is applied.

I think it is important to keep existing behavior, set default memmachine project sounds great to me!
And this also reminds me one feedback from pengfei earlier. He unzips the code downloaded from release into a new folder, the script memmachine-compose.sh start fails to load previous volumes because the project namespace has changed. i once asked him to set COMPOSE_PROJECT_NAME=memmachine

And I checked qa test code, specific container names are used in tests to check container statuses. Note that there will be effort expected to update test code to align with new naming of containers. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Explicit network and container name

4 participants