feat: integrate ContainerDetector for improved container detection in ElastiCache, ECS, and RDS managers#343
Merged
hectorvent merged 1 commit intofloci-io:mainfrom Apr 11, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a centralized ContainerDetector to determine whether Floci is running inside a container, and wires that detection into container-backend startup logic (ElastiCache, ECS, RDS) and Docker host resolution.
Changes:
- Added
ContainerDetectorwith multiple heuristics (marker files, env vars, cgroup, mountinfo) and a cached result. - Updated ElastiCache/ECS/RDS container managers to use
ContainerDetectorto decide between host port publishing vs using container IPs. - Moved/updated
DockerHostResolverto rely onContainerDetector, and added unit tests for container detection.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/io/github/hectorvent/floci/core/common/docker/ContainerDetector.java | New container-runtime detection utility with cached evaluation. |
| src/test/java/io/github/hectorvent/floci/core/common/docker/ContainerDetectorTest.java | Unit tests covering the detection heuristics and caching behavior. |
| src/main/java/io/github/hectorvent/floci/core/common/docker/DockerHostResolver.java | Uses ContainerDetector instead of ad-hoc marker/cgroup logic to pick container-to-host address. |
| src/main/java/io/github/hectorvent/floci/services/elasticache/container/ElastiCacheContainerManager.java | Uses ContainerDetector to choose port binding vs container IP for backend connectivity. |
| src/main/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManager.java | Uses ContainerDetector to decide whether to publish ports and how to compute network bindings. |
| src/main/java/io/github/hectorvent/floci/services/rds/container/RdsContainerManager.java | Uses ContainerDetector to choose port binding vs container IP for backend connectivity. |
| src/main/java/io/github/hectorvent/floci/services/lambda/launcher/ContainerLauncher.java | Updates import to the new DockerHostResolver package. |
Comments suppressed due to low confidence (3)
src/main/java/io/github/hectorvent/floci/services/elasticache/container/ElastiCacheContainerManager.java:171
- When a user configures
dockerNetwork/networkModeashost, Docker rejects containers that also specify port bindings ("conflicting options: port publishing and the container type network mode"). With the new!containerDetector.isRunningInContainer()condition, port bindings are now added for all host runs, which can break the previously-workingnetworkMode=hostsetup on native Linux. Consider skipping port bindings when the configured network mode ishost(and other incompatible modes), or compute the bind/inspect strategy after resolving the effective network mode instead of basing it solely onisRunningInContainer().
private HostConfig buildHostConfig() {
HostConfig hostConfig = HostConfig.newHostConfig();
if (!containerDetector.isRunningInContainer()) {
// Bind BACKEND_PORT → random host port so the JVM can reach the container
int freePort = findFreePort();
Ports portBindings = new Ports();
portBindings.bind(ExposedPort.tcp(BACKEND_PORT), Ports.Binding.bindPort(freePort));
hostConfig.withPortBindings(portBindings);
LOG.debugv("Native mode: binding container port 6379 → host port {0}", freePort);
src/main/java/io/github/hectorvent/floci/services/rds/container/RdsContainerManager.java:174
- Same issue as ElastiCache: if
dockerNetwork/networkModeis set tohost, Docker does not allow port bindings. Since port bindings are now applied whenever Floci is not running in a container, starting an RDS backend withnetworkMode=hostcan fail on native Linux. Please gate port-binding logic on the effective network mode (skip forhost/other incompatible modes) rather than only onisRunningInContainer().
private HostConfig buildHostConfig(int enginePort) {
HostConfig hostConfig = HostConfig.newHostConfig();
if (!containerDetector.isRunningInContainer()) {
int freePort = findFreePort();
Ports portBindings = new Ports();
portBindings.bind(ExposedPort.tcp(enginePort), Ports.Binding.bindPort(freePort));
hostConfig.withPortBindings(portBindings);
LOG.debugv("Native mode: binding container port {0} → host port {1}", enginePort, freePort);
}
src/main/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManager.java:183
- Port bindings are applied whenever Floci is not running in a container, but Docker forbids publishing ports when
HostConfig.networkModeishost. Since the ECS container network mode can be set via config, this can make task startup fail fordockerNetwork=hoston native Linux. Consider determining the effective network mode first and skippingwithPortBindings(...)when it ishost(or other incompatible modes).
private HostConfig buildHostConfig(ContainerDefinition def, List<ExposedPort> exposedPorts) {
HostConfig hostConfig = HostConfig.newHostConfig();
if (def.getMemory() != null) {
hostConfig.withMemory((long) def.getMemory() * 1024 * 1024);
}
if (!containerDetector.isRunningInContainer() && !exposedPorts.isEmpty()) {
Ports portBindings = new Ports();
for (ExposedPort ep : exposedPorts) {
portBindings.bind(ep, Ports.Binding.bindPort(0)); // 0 = dynamic host port
}
hostConfig.withPortBindings(portBindings);
}
Collaborator
|
@cfranzen conflicts need to be resolved |
… ElastiCache, ECS, and RDS managers
7ee80e1 to
d87ee89
Compare
Contributor
Author
|
@hectorvent just resolved it a minute ago |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Added ContainerDetector for improved detection if Floci is running inside a container. All services that start up container backends use this detector now.
Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
Not requied
Checklist
./mvnw testpasses locally