Skip to content

Commit

Permalink
Fix port mapping after container restart
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Aug 28, 2024
1 parent 977da7e commit c34efe0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/app/container/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,27 @@ func (m *Manager) ProdReload(excludeGlob []string, dryRun bool) error {
if err != nil {
return fmt.Errorf("error starting container: %w", err)
}

// Fetch port number after starting the container
containers, err = m.command.GetContainers(m.systemConfig, containerName, true)
if err != nil {
return fmt.Errorf("error getting running containers: %w", err)
}
m.hostPort = containers[0].Port

if m.health != "" {
err = m.WaitForHealth(m.GetHealthUrl())
if err != nil {
return fmt.Errorf("error waiting for health: %w", err)
}
}
} else {
// TODO handle case where image name is specified and param values change, need to restart container in that case
m.hostPort = containers[0].Port
m.Debug().Msg("container already running")
}

m.hostPort = containers[0].Port
m.Debug().Msgf("updating port to %d", m.hostPort)
return nil
}

Expand Down

0 comments on commit c34efe0

Please sign in to comment.