Skip to content

Commit

Permalink
- Added functionality to check if running inside/within a docker envi…
Browse files Browse the repository at this point in the history
…ronment
  • Loading branch information
DavidArayan committed Feb 15, 2024
1 parent b0c5a92 commit 7982844
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk-core/src/core/util/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export class DNS {
return accept(hostname);
}

// check if inside docker in lambda - use host.docker.internal if so
if (Util.isDocker()) {
return accept(`${url.protocol}//${'host.docker.internal'}${(url.port !== '' ? `:${url.port}` : '')}${(url.pathname !== '/' ? url.pathname : '')}`);
}

// resolve localhost to an ip-address
// this is needed for example in docker environments
import('os').then((os) => {
Expand Down
4 changes: 4 additions & 0 deletions sdk-core/src/core/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class Util {
return (typeof process !== 'undefined') && (process.release.name === 'node');
}

public static isDocker(): boolean {
return Util.isNode() && process.env['LAMBDA_TASK_ROOT'] ? true : false;
}

public static parseBool(value: any): boolean {
if (!value) {
return false;
Expand Down

0 comments on commit 7982844

Please sign in to comment.