run: bind mount /etc/hosts and /etc/resolv.conf if not in a volume
change the logic for bind mounting /etc/hosts and /etc/resolv.conf in the container. Now they are not bind mounted when they are specified as volumes, so it is still possible to have them writeable in the container. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #1156 Approved by: rhatdan
This commit is contained in:
parent
68ee943fac
commit
3cebe4f2c4
18
run.go
18
run.go
|
@ -1062,8 +1062,9 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
|||
|
||||
bindFiles := make(map[string]string)
|
||||
namespaceOptions := append(b.NamespaceOptions, options.NamespaceOptions...)
|
||||
networkNamespace := namespaceOptions.Find(string(specs.NetworkNamespace))
|
||||
if networkNamespace == nil || networkNamespace.Host || networkNamespace.Path != "" {
|
||||
volumes := b.Volumes()
|
||||
|
||||
if !contains(volumes, "/etc/hosts") {
|
||||
hostFile, err := b.addNetworkConfig(path, "/etc/hosts", rootIDPair)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1073,7 +1074,9 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
|||
if err := addHostsToFile(b.CommonBuildOpts.AddHost, hostFile); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !contains(volumes, "/etc/resolv.conf") {
|
||||
resolvFile, err := b.addNetworkConfig(path, "/etc/resolv.conf", rootIDPair)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1081,7 +1084,7 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
|||
bindFiles["/etc/resolv.conf"] = resolvFile
|
||||
}
|
||||
|
||||
err = b.setupMounts(mountPoint, spec, path, options.Mounts, bindFiles, b.Volumes(), b.CommonBuildOpts.Volumes, b.CommonBuildOpts.ShmSize, namespaceOptions)
|
||||
err = b.setupMounts(mountPoint, spec, path, options.Mounts, bindFiles, volumes, b.CommonBuildOpts.Volumes, b.CommonBuildOpts.ShmSize, namespaceOptions)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error resolving mountpoints for container %q", b.ContainerID)
|
||||
}
|
||||
|
@ -1136,6 +1139,15 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func contains(volumes []string, v string) bool {
|
||||
for _, i := range volumes {
|
||||
if i == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func checkAndOverrideIsolationOptions(isolation Isolation, options *RunOptions) error {
|
||||
switch isolation {
|
||||
case IsolationOCIRootless:
|
||||
|
|
Loading…
Reference in New Issue