Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Matching Docker containers by name only (fixes #170)
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Jul 18, 2018
1 parent 2e766f3 commit 9571e4d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions selenoid/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,30 +588,26 @@ func (c *DockerConfigurator) IsRunning() bool {
}

func (c *DockerConfigurator) getSelenoidContainer() *types.Container {
return c.getContainer(selenoidContainerName, c.Port)
return c.getContainer(selenoidContainerName)
}

func (c *DockerConfigurator) IsUIRunning() bool {
return c.getSelenoidUIContainer() != nil
}

func (c *DockerConfigurator) getSelenoidUIContainer() *types.Container {
return c.getContainer(selenoidUIContainerName, c.Port)
return c.getContainer(selenoidUIContainerName)
}

func (c *DockerConfigurator) getContainer(name string, port int) *types.Container {
func (c *DockerConfigurator) getContainer(name string) *types.Container {
f := filters.NewArgs()
f.Add("name", name)
containers, err := c.docker.ContainerList(context.Background(), types.ContainerListOptions{Filters: f})
if err != nil {
return nil
}
for _, c := range containers {
for _, p := range c.Ports {
if p.PublicPort == uint16(port) {
return &c
}
}
if len(containers) > 0 {
return &containers[0]
}
return nil
}
Expand Down Expand Up @@ -752,14 +748,18 @@ func (c *DockerConfigurator) StartUI() error {

var cmd, links []string
var selenoidUri string
for containerName, port := range map[string]int{
selenoidContainerName: SelenoidDefaultPort,
ggrUIContainerName: GgrUIDefaultPort,
containers:
for _, containerName := range []string{
selenoidContainerName, ggrUIContainerName,
} {
if c.getContainer(containerName, port) != nil {
selenoidUri = fmt.Sprintf("--selenoid-uri=http://%s:%d", containerName, port)
links = []string{containerName}
break
if ctr := c.getContainer(containerName); ctr != nil {
for _, p := range ctr.Ports {
if p.PublicPort != 0 {
selenoidUri = fmt.Sprintf("--selenoid-uri=http://%s:%d", containerName, p.PublicPort)
links = []string{containerName}
break containers
}
}
}
}
overrideCmd := strings.Fields(c.Args)
Expand Down

0 comments on commit 9571e4d

Please sign in to comment.