Skip to content

Commit 3043001

Browse files
committed
Label /etc/resolv.conf, /etc/hosts ... correctly in shared network containers
If I run two containers with the same network they share the same /etc/resolv.conf. The current code changes the labels of the /etc/resolv.conf currently to the private label which causes it to be unusable in the first container. This patch changes the labels to a shared label if more then one container will use the content. Docker-DCO-1.1-Signed-off-by: Dan Walsh <[email protected]> (github: rhatdan)
1 parent a461cc8 commit 3043001

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

daemon/container.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,12 @@ func copyEscapable(dst io.Writer, src io.ReadCloser) (written int64, err error)
10611061

10621062
func (container *Container) networkMounts() []execdriver.Mount {
10631063
var mounts []execdriver.Mount
1064+
mode := "Z"
1065+
if container.hostConfig.NetworkMode.IsContainer() {
1066+
mode = "z"
1067+
}
10641068
if container.ResolvConfPath != "" {
1065-
label.SetFileLabel(container.ResolvConfPath, container.MountLabel)
1069+
label.Relabel(container.ResolvConfPath, container.MountLabel, mode)
10661070
mounts = append(mounts, execdriver.Mount{
10671071
Source: container.ResolvConfPath,
10681072
Destination: "/etc/resolv.conf",
@@ -1071,7 +1075,7 @@ func (container *Container) networkMounts() []execdriver.Mount {
10711075
})
10721076
}
10731077
if container.HostnamePath != "" {
1074-
label.SetFileLabel(container.HostnamePath, container.MountLabel)
1078+
label.Relabel(container.HostnamePath, container.MountLabel, mode)
10751079
mounts = append(mounts, execdriver.Mount{
10761080
Source: container.HostnamePath,
10771081
Destination: "/etc/hostname",
@@ -1080,7 +1084,7 @@ func (container *Container) networkMounts() []execdriver.Mount {
10801084
})
10811085
}
10821086
if container.HostsPath != "" {
1083-
label.SetFileLabel(container.HostsPath, container.MountLabel)
1087+
label.Relabel(container.HostsPath, container.MountLabel, mode)
10841088
mounts = append(mounts, execdriver.Mount{
10851089
Source: container.HostsPath,
10861090
Destination: "/etc/hosts",

0 commit comments

Comments
 (0)