@@ -163,8 +163,8 @@ async function createDockerProxy(proxyPort: number, httpsConfig: { certPath: str
163
163
"message" : `Conflict. The container name ${
164
164
containerName
165
165
} is already in use by a running container.\n${ ''
166
- } HTTP Toolkit won't intercept this by default to avoid conflicts with shared resources. ${ ''
167
- } To create & intercept this container, either stop the existing unintercepted container, or use a different name.`
166
+ } HTTP Toolkit won't intercept this by default to avoid conflicts over shared resources. ${ ''
167
+ } To create & intercept this container, either stop the existing unintercepted container, or use a different container name.`
168
168
} ) ) ;
169
169
return ;
170
170
} else if ( existingContainer || hasDockerComposeLabels ) {
@@ -185,12 +185,34 @@ async function createDockerProxy(proxyPort: number, httpsConfig: { certPath: str
185
185
const startContainerMatch = START_CONTAINER_MATCHER . exec ( reqPath ) ;
186
186
if ( startContainerMatch ) {
187
187
const containerId = startContainerMatch [ 1 ] ;
188
- if ( ! isInterceptedContainer ( await docker . getContainer ( containerId ) . inspect ( ) , proxyPort ) ) {
188
+ const containerData = await docker . getContainer ( containerId ) . inspect ( ) ;
189
+
190
+ if ( ! isInterceptedContainer ( containerData , proxyPort ) ) {
189
191
res . writeHead ( 400 ) . end (
190
192
"HTTP Toolkit cannot intercept startup of preexisting non-intercepted containers. " +
191
193
"The container must be recreated here first - try `docker run <image>` instead."
192
194
) ;
193
195
}
196
+
197
+ if ( containerData . Name . endsWith ( `_HTK${ proxyPort } ` ) ) {
198
+ // Trim initial slash and our HTK suffix:
199
+ const clonedContainerName = containerData . Name . slice ( 1 , - 1 * `_HTK${ proxyPort } ` . length ) ;
200
+ const clonedContainerData = await docker . getContainer ( clonedContainerName )
201
+ . inspect ( )
202
+ . catch ( ( ) => undefined ) ;
203
+
204
+ if ( clonedContainerData && clonedContainerData . State . Running ) {
205
+ // If you successfully intercept a docker-compose container, stop it & start the original container(s),
206
+ // and then restart the already-created intercepted container, you could risk conflicts, so we warn you:
207
+ res . writeHead ( 409 ) . end (
208
+ `Conflict: an unintercepted container with the same base name is already running.\n${ ''
209
+ } HTTP Toolkit won't launch intercepted containers in parallel by default to avoid conflicts ${ ''
210
+ } over shared resources. To create & intercept this container, either stop the existing ${ ''
211
+ } unintercepted container, or use a different container name.`
212
+
213
+ ) ;
214
+ }
215
+ }
194
216
}
195
217
196
218
if (
0 commit comments