@@ -23,7 +23,7 @@ import { ensureDockerInjectionVolumeExists } from './docker-data-injection';
23
23
24
24
let dockerAvailableCache : Promise < boolean > | undefined ;
25
25
26
- export const isDockerAvailable = ( ) => {
26
+ export const isDockerAvailable = ( options : { logError ?: boolean } = { } ) => {
27
27
if ( dockerAvailableCache ) return dockerAvailableCache ;
28
28
else {
29
29
dockerAvailableCache = ( async ( ) => { // Catch sync & async setup errors
@@ -33,13 +33,15 @@ export const isDockerAvailable = () => {
33
33
if ( info . OSType === 'windows' ) {
34
34
// We don't support Windows containers yet (and I think they're very rarely
35
35
// used anyway) so we treat Windows-mode Docker as unavailable:
36
- console . warn ( "Docker is running in Windows container mode - not supported" ) ;
37
- return false ;
36
+ throw new Error ( "Docker running in Windows container mode - not supported" ) ;
38
37
} else {
39
38
return true ;
40
39
}
41
40
} )
42
- . catch ( ( ) => false ) ;
41
+ . catch ( ( error ) => {
42
+ if ( options . logError ) console . warn ( 'Docker not available:' , error . message ) ;
43
+ return false ;
44
+ } ) ;
43
45
44
46
// Cache the resulting status for 3 seconds:
45
47
setTimeout ( ( ) => { dockerAvailableCache = undefined ; } , 3000 ) ;
@@ -74,11 +76,9 @@ export async function startDockerInterceptionServices(
74
76
}
75
77
76
78
// Log if Docker was not available at proxy start, and why, for debugging later:
77
- ( async ( ) => { // Catch sync & async setup errors
78
- await new Docker ( ) . ping ( ) ;
79
- console . log ( 'Connected to Docker' ) ;
80
- } ) ( ) . catch ( ( error ) => {
81
- console . warn ( `Docker not available: ${ error . message } ` ) ;
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
82
82
} ) ;
83
83
84
84
const networkMonitor = monitorDockerNetworkAliases ( proxyPort ) ;
0 commit comments