remove container-names from compose#1141
remove container-names from compose#1141ChristianKniep wants to merge 4 commits intoMemMachine:mainfrom
Conversation
|
Two bridges are created with two stacks side-by-side: |
b7fc40a to
a542c2e
Compare
There was a problem hiding this comment.
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_namedirectives 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 execwith service names instead ofdocker execwith 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.
sscargal
left a comment
There was a problem hiding this comment.
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
.envvalue forCOMPOSE_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).
-
User supplies ports per instance (simplest, most transparent)
- stack A: defaults
- stack B: POSTGRES_PORT=5433 MEMORY_SERVER_PORT=8081 ...
-
Script computes ports from an “instance number”
-
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.she.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.
|
In my case I used different directories (using The ports can already be overwritten using there environment vars
Thus, when using a single stack nothing will change. |
|
|
|
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 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. |
Purpose of the change
Removing
container-nameand 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-nameand explicit network nameFixes/Closes
Fixes #1140
Type of change
[Please delete options that are not relevant.]
How Has This Been Tested?
Change the
docker execuse in the memmachine-compose script.Checklist
[Please delete options that are not relevant.]
Maintainer Checklist
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".]