Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support returning all IP addresses of a container #553

Merged
merged 6 commits into from
Oct 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,23 @@ func (c *DockerContainer) ContainerIP(ctx context.Context) (string, error) {
return ip, nil
}

// ContainerIPList gets the IP addresses of all the networks within the container.
func (c *DockerContainer) ContainerIPList(ctx context.Context) ([]string, error) {
gauravgahlot marked this conversation as resolved.
Show resolved Hide resolved
ipList := make([]string, 0)
gauravgahlot marked this conversation as resolved.
Show resolved Hide resolved

inspect, err := c.inspectContainer(ctx)
if err != nil {
return nil, err
}

networks := inspect.NetworkSettings.Networks
for _, endpoints := range networks {
ipList = append(ipList, endpoints.IPAddress)
gauravgahlot marked this conversation as resolved.
Show resolved Hide resolved
}

return ipList, nil
gauravgahlot marked this conversation as resolved.
Show resolved Hide resolved
}

// NetworkAliases gets the aliases of the container for the networks it is attached to.
func (c *DockerContainer) NetworkAliases(ctx context.Context) (map[string][]string, error) {
inspect, err := c.inspectContainer(ctx)
Expand Down