Skip to content

Commit 9d3355f

Browse files
committed
Handle more filter formats in Docker proxy
1 parent 565e1d1 commit 9d3355f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/interceptors/docker/docker-proxy.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,18 @@ async function createDockerProxy(proxyPort: number, httpsConfig: { certPath: str
189189
const filterString = reqUrl.searchParams.get('filters') ?? '{}';
190190

191191
try {
192-
const filters = JSON.parse(filterString) as { [key: string]: string[] };
193-
const projectFilter = (filters.label ?? [])
194-
.filter(l => l.startsWith("com.docker.compose.project="))[0];
192+
const filters = JSON.parse(filterString) as {
193+
// Docs say only string[] is allowed, but Docker CLI uses bool maps in "docker compose"
194+
[key: string]: string[] | { [key: string]: boolean }
195+
};
196+
const labelFilters = (
197+
_.isArray(filters.label)
198+
? filters.label
199+
: Object.keys(filters.label)
200+
.filter(key => !!(filters.label as _.Dictionary<boolean>)[key])
201+
);
202+
const projectFilter = labelFilters.filter(l => l.startsWith("com.docker.compose.project="))[0];
203+
195204
if (projectFilter) {
196205
const project = projectFilter.slice(projectFilter.indexOf('=') + 1);
197206

@@ -206,7 +215,7 @@ async function createDockerProxy(proxyPort: number, httpsConfig: { certPath: str
206215
// containers, and b) future non-proxied requests only find non-intercepted containers.
207216
// By excluding non-intercepted containers, we force DC to recreate, so we can then
208217
// intercept the container creation itself and inject what we need.
209-
...filters.label.filter((label) => label !== projectFilter),
218+
...labelFilters.filter((label) => label !== projectFilter),
210219
`com.docker.compose.project=${project}_HTK:${proxyPort}`
211220
]
212221
}));

0 commit comments

Comments
 (0)