mirror of
https://github.com/containers/podman.git
synced 2025-09-19 12:56:57 +08:00
add hostname to network alias
We use the name as alias but using the hostname makes also sense and this is what docker does. We have to keep the short id as well for docker compat. While adding some tests I removed some duplicated tests that were executed twice for nv for no reason. Fixes #17370 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -513,8 +513,7 @@ func (c *Container) NetworkConnect(nameOrID, netName string, netOpts types.PerNe
|
||||
// get network status before we connect
|
||||
networkStatus := c.getNetworkStatus()
|
||||
|
||||
// always add the short id as alias for docker compat
|
||||
netOpts.Aliases = append(netOpts.Aliases, c.config.ID[:12])
|
||||
netOpts.Aliases = append(netOpts.Aliases, getExtraNetworkAliases(c)...)
|
||||
|
||||
if netOpts.InterfaceName == "" {
|
||||
netOpts.InterfaceName = getFreeInterfaceName(networks)
|
||||
@ -639,6 +638,16 @@ func getFreeInterfaceName(networks map[string]types.PerNetworkOptions) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func getExtraNetworkAliases(c *Container) []string {
|
||||
// always add the short id as alias for docker compat
|
||||
alias := []string{c.config.ID[:12]}
|
||||
// if an explicit hostname was set add it as well
|
||||
if c.config.Spec.Hostname != "" {
|
||||
alias = append(alias, c.config.Spec.Hostname)
|
||||
}
|
||||
return alias
|
||||
}
|
||||
|
||||
// DisconnectContainerFromNetwork removes a container from its network
|
||||
func (r *Runtime) DisconnectContainerFromNetwork(nameOrID, netName string, force bool) error {
|
||||
ctr, err := r.LookupContainer(nameOrID)
|
||||
|
Reference in New Issue
Block a user