Skip to content

Commit

Permalink
fix: Auto expose port on macOS to make it accessible on the host
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Knorr <[email protected]>
  • Loading branch information
juliusknorr committed Jan 9, 2025
1 parent 4827fbb commit 48f0e31
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,17 @@ export async function startNextcloud(branch = 'master', mountApp: boolean|string
}],
}

// On macOS we need to expose the port since the docker container is running within a VM
const autoExposePort = process.platform === 'darwin'

const container = await docker.createContainer({
Image: SERVER_IMAGE,
name: getContainerName(),
Env: [`BRANCH=${branch}`, 'APCU=1'],
HostConfig: {
Binds: mounts.length > 0 ? mounts : undefined,
PortBindings,
PublishAllPorts: autoExposePort,
// Mount data directory in RAM for faster IO
Mounts: [{
Target: '/var/www/html/data',
Expand Down Expand Up @@ -326,6 +330,13 @@ export const stopNextcloud = async function() {
export const getContainerIP = async function(
container = getContainer()
): Promise<string> {
const containerInspect = await container.inspect()
const hostPort = containerInspect.NetworkSettings.Ports['80/tcp']?.[0]?.HostPort

if (hostPort) {
return `localhost:${hostPort}`
}

let ip = ''
let tries = 0
while (ip === '' && tries < 10) {
Expand Down

0 comments on commit 48f0e31

Please sign in to comment.