mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(ecs): honor task portMappings hostPort when launching containers (#1610)
ECS task definitions can declare portMappings with an explicit hostPort, which AWS bridge mode publishes so the app is reachable on the host at localhost:<hostPort>. Floci parsed the value but discarded it at launch: EcsContainerManager.startTask always called withDynamicPort() (random host port) in native mode, and withExposedPort() (no host binding at all, docker inspect shows "<port>/tcp": null) when Floci runs inside Docker. Either way the requested hostPort was never applied, so containers ran but were unreachable from the host. Honor an explicit hostPort by binding it as a fixed host port via withPortBinding(containerPort, hostPort), publishing in both native and in-container modes (mirroring the ECR registry's fixed-port publishing). A hostPort of 0/unset keeps the prior behavior: dynamic host port in native mode, exposed-only when running inside Docker. Adds EcsContainerManagerPortMappingsTest (mocked builder, no Docker daemon required) covering all three branches. Fixes #1270
This commit is contained in:
1 parent
239bc52e06
commit
1dc48eca39
2 files changed
+140
-3
No files matched your search
+9
-3
@@ -120,12 +120,18 @@ public class EcsContainerManager {
|
||||
specBuilder.withMemoryMb(def.getMemory());
|
||||
}
|
||||
|
||||
// Add port mappings. Publish to host only in native mode; in Docker
|
||||
// mode ECS consumers reach containers via the docker network IP.
|
||||
// Add port mappings. An explicit hostPort is always published to the
|
||||
// Docker host so the service is reachable at localhost:<hostPort>,
|
||||
// matching AWS bridge mode (mirrors the ECR registry's fixed-port
|
||||
// publishing). When no hostPort is requested, publish a dynamic host
|
||||
// port in native mode; in Docker mode only expose the port, since ECS
|
||||
// consumers reach containers via the docker network IP.
|
||||
if (def.getPortMappings() != null) {
|
||||
boolean publishToHost = !containerDetector.isRunningInContainer();
|
||||
for (PortMapping pm : def.getPortMappings()) {
|
||||
if (publishToHost) {
|
||||
if (pm.hostPort() > 0) {
|
||||
specBuilder.withPortBinding(pm.containerPort(), pm.hostPort());
|
||||
} else if (publishToHost) {
|
||||
specBuilder.withDynamicPort(pm.containerPort());
|
||||
} else {
|
||||
specBuilder.withExposedPort(pm.containerPort());
|
||||
|
||||
Reference in new issue
Block a user