File tree Expand file tree Collapse file tree 3 files changed +32
-16
lines changed Expand file tree Collapse file tree 3 files changed +32
-16
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { ProxySettingCallback } from 'mockttp';
44import { logError } from '../../error-tracking' ;
55import { addShutdownHandler } from '../../shutdown' ;
66
7+ import { getDockerAddress } from './docker-utils' ;
78import { DOCKER_BUILD_LABEL } from './docker-build-injection' ;
89import { DOCKER_CONTAINER_LABEL } from './docker-commands' ;
910
@@ -76,9 +77,16 @@ export async function startDockerInterceptionServices(
7677 }
7778
7879 // Log if Docker was not available at proxy start, and why, for debugging later:
79- isDockerAvailable ( { logError : true } ) . then ( ( isAvailable ) => {
80- if ( isAvailable ) console . log ( 'Connected to Docker' ) ;
81- // logError will log the specific not-available error, if this failed
80+ isDockerAvailable ( { logError : true } ) . then ( async ( isAvailable ) => {
81+ if ( isAvailable ) {
82+ const dockerAddress = await getDockerAddress ( new Docker ( ) ) ;
83+ console . log ( `Connected to Docker at ${
84+ 'socketPath' in dockerAddress
85+ ? dockerAddress . socketPath
86+ : `tcp://${ dockerAddress . host } :${ dockerAddress . port } `
87+ } `) ;
88+ }
89+ // logError:true will log the specific not-available error, if this failed
8290 } ) ;
8391
8492 const networkMonitor = monitorDockerNetworkAliases ( proxyPort ) ;
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { streamToBuffer } from '../../util/stream';
1414import { logError } from '../../error-tracking' ;
1515import { addShutdownHandler } from '../../shutdown' ;
1616
17+ import { getDockerAddress } from './docker-utils' ;
1718import {
1819 isInterceptedContainer ,
1920 transformContainerCreationConfig
@@ -76,18 +77,7 @@ async function createDockerProxy(
7677) {
7778 const docker = new Dockerode ( ) ;
7879
79- // Hacky logic to reuse docker-modem's internal env + OS parsing logic to
80- // work out where the local Docker host is:
81- const modem = docker . modem as any as ( {
82- getSocketPath ( ) : undefined | Promise < string > ;
83- host : string ;
84- port : number ;
85- } ) ;
86-
87- const modemSocketPath = await modem . getSocketPath ( ) ;
88- const dockerHostOptions = modemSocketPath
89- ? { socketPath : modemSocketPath }
90- : { host : modem . host , port : modem . port } ;
80+ const dockerHostOptions = await getDockerAddress ( docker ) ;
9181
9282 const agent = new http . Agent ( { keepAlive : true } ) ;
9383
Original file line number Diff line number Diff line change @@ -15,4 +15,22 @@ export const waitForDockerStream = (
1515
1616 resolve ( ) ;
1717 } ) ;
18- } ) ;
18+ } ) ;
19+
20+ export const getDockerAddress = async ( docker : Docker ) : Promise <
21+ | { socketPath : string }
22+ | { host : string , port : number }
23+ > => {
24+ // Hacky logic to reuse docker-modem's internal env + OS parsing logic to
25+ // work out where the local Docker host is:
26+ const modem = docker . modem as any as ( {
27+ getSocketPath ( ) : undefined | Promise < string > ;
28+ host : string ;
29+ port : number ;
30+ } ) ;
31+
32+ const modemSocketPath = await modem . getSocketPath ( ) ;
33+ return modemSocketPath
34+ ? { socketPath : modemSocketPath }
35+ : { host : modem . host , port : modem . port } ;
36+ }
You can’t perform that action at this time.
0 commit comments