mirror of
https://github.com/containers/podman.git
synced 2025-10-19 20:23:08 +08:00
podman: support --mount type=devpts
Allow to create a devpts mount. This is useful for containers that bind mount /dev/ from the host but at the same time want to create a terminal. It can be used as: podman run -v /dev:/dev --mount type=devpts,target=/dev/pts ... Closes: https://github.com/containers/podman/issues/6804 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -20,6 +20,8 @@ const (
|
|||||||
TypeVolume = "volume"
|
TypeVolume = "volume"
|
||||||
// TypeTmpfs is the type for mounting tmpfs
|
// TypeTmpfs is the type for mounting tmpfs
|
||||||
TypeTmpfs = "tmpfs"
|
TypeTmpfs = "tmpfs"
|
||||||
|
// TypeDevpts is the type for creating a devpts
|
||||||
|
TypeDevpts = "devpts"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -197,6 +199,15 @@ func getMounts(mountFlag []string) (map[string]spec.Mount, map[string]*specgen.N
|
|||||||
return nil, nil, errors.Wrapf(errDuplicateDest, mount.Destination)
|
return nil, nil, errors.Wrapf(errDuplicateDest, mount.Destination)
|
||||||
}
|
}
|
||||||
finalMounts[mount.Destination] = mount
|
finalMounts[mount.Destination] = mount
|
||||||
|
case TypeDevpts:
|
||||||
|
mount, err := getDevptsMount(tokens)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if _, ok := finalMounts[mount.Destination]; ok {
|
||||||
|
return nil, nil, errors.Wrapf(errDuplicateDest, mount.Destination)
|
||||||
|
}
|
||||||
|
finalMounts[mount.Destination] = mount
|
||||||
case "volume":
|
case "volume":
|
||||||
volume, err := getNamedVolume(tokens)
|
volume, err := getNamedVolume(tokens)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -416,6 +427,39 @@ func getTmpfsMount(args []string) (spec.Mount, error) {
|
|||||||
return newMount, nil
|
return newMount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse a single devpts mount entry from the --mount flag
|
||||||
|
func getDevptsMount(args []string) (spec.Mount, error) {
|
||||||
|
newMount := spec.Mount{
|
||||||
|
Type: TypeDevpts,
|
||||||
|
Source: TypeDevpts,
|
||||||
|
}
|
||||||
|
|
||||||
|
var setDest bool
|
||||||
|
|
||||||
|
for _, val := range args {
|
||||||
|
kv := strings.Split(val, "=")
|
||||||
|
switch kv[0] {
|
||||||
|
case "target", "dst", "destination":
|
||||||
|
if len(kv) == 1 {
|
||||||
|
return newMount, errors.Wrapf(optionArgError, kv[0])
|
||||||
|
}
|
||||||
|
if err := parse.ValidateVolumeCtrDir(kv[1]); err != nil {
|
||||||
|
return newMount, err
|
||||||
|
}
|
||||||
|
newMount.Destination = filepath.Clean(kv[1])
|
||||||
|
setDest = true
|
||||||
|
default:
|
||||||
|
return newMount, errors.Wrapf(util.ErrBadMntOption, kv[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !setDest {
|
||||||
|
return newMount, noDestError
|
||||||
|
}
|
||||||
|
|
||||||
|
return newMount, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Parse a single volume mount entry from the --mount flag.
|
// Parse a single volume mount entry from the --mount flag.
|
||||||
// Note that the volume-label option for named volumes is currently NOT supported.
|
// Note that the volume-label option for named volumes is currently NOT supported.
|
||||||
// TODO: add support for --volume-label
|
// TODO: add support for --volume-label
|
||||||
|
@ -494,7 +494,7 @@ Tune a container's memory swappiness behavior. Accepts an integer between 0 and
|
|||||||
|
|
||||||
Attach a filesystem mount to the container
|
Attach a filesystem mount to the container
|
||||||
|
|
||||||
Current supported mount TYPES are `bind`, `volume`, and `tmpfs`. <sup>[[1]](#Footnote1)</sup>
|
Current supported mount TYPES are `bind`, `volume`, `tmpfs` and `devpts`. <sup>[[1]](#Footnote1)</sup>
|
||||||
|
|
||||||
e.g.
|
e.g.
|
||||||
|
|
||||||
@ -506,6 +506,8 @@ Current supported mount TYPES are `bind`, `volume`, and `tmpfs`. <sup>[[1]](#Foo
|
|||||||
|
|
||||||
type=tmpfs,tmpfs-size=512M,destination=/path/in/container
|
type=tmpfs,tmpfs-size=512M,destination=/path/in/container
|
||||||
|
|
||||||
|
type=devpts,destination=/dev/pts
|
||||||
|
|
||||||
Common Options:
|
Common Options:
|
||||||
|
|
||||||
· src, source: mount source spec for bind and volume. Mandatory for bind.
|
· src, source: mount source spec for bind and volume. Mandatory for bind.
|
||||||
|
@ -501,7 +501,7 @@ Tune a container's memory swappiness behavior. Accepts an integer between *0* an
|
|||||||
|
|
||||||
Attach a filesystem mount to the container
|
Attach a filesystem mount to the container
|
||||||
|
|
||||||
Current supported mount TYPEs are **bind**, **volume**, and **tmpfs**. <sup>[[1]](#Footnote1)</sup>
|
Current supported mount TYPEs are **bind**, **volume**, **tmpfs** and **devpts**. <sup>[[1]](#Footnote1)</sup>
|
||||||
|
|
||||||
e.g.
|
e.g.
|
||||||
|
|
||||||
@ -513,6 +513,8 @@ Current supported mount TYPEs are **bind**, **volume**, and **tmpfs**. <sup>[[1]
|
|||||||
|
|
||||||
type=tmpfs,tmpfs-size=512M,destination=/path/in/container
|
type=tmpfs,tmpfs-size=512M,destination=/path/in/container
|
||||||
|
|
||||||
|
type=devpts,destination=/dev/pts
|
||||||
|
|
||||||
Common Options:
|
Common Options:
|
||||||
|
|
||||||
· src, source: mount source spec for bind and volume. Mandatory for bind.
|
· src, source: mount source spec for bind and volume. Mandatory for bind.
|
||||||
|
@ -811,6 +811,14 @@ USER mail`
|
|||||||
Expect(len(session.OutputToStringArray())).To(Equal(1))
|
Expect(len(session.OutputToStringArray())).To(Equal(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman run --mount type=devpts,target=/foo/bar", func() {
|
||||||
|
SkipIfRootless()
|
||||||
|
session := podmanTest.Podman([]string{"run", "--mount", "type=devpts,target=/foo/bar", fedoraMinimal, "stat", "-f", "-c%T", "/foo/bar"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring("devpts"))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman run --pod automatically", func() {
|
It("podman run --pod automatically", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "-d", "--pod", "new:foobar", ALPINE, "nc", "-l", "-p", "8080"})
|
session := podmanTest.Podman([]string{"run", "-d", "--pod", "new:foobar", ALPINE, "nc", "-l", "-p", "8080"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user