Skip to content

Commit 18768fd

Browse files
committed
api: add TypeTmpfs to api/types/mount
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 9e206b5 commit 18768fd

File tree

14 files changed

+382
-38
lines changed

14 files changed

+382
-38
lines changed

api/types/mount/mount.go

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
package mount
22

3+
import (
4+
"os"
5+
)
6+
37
// Type represents the type of a mount.
48
type Type string
59

10+
// Type constants
611
const (
7-
// TypeBind BIND
12+
// TypeBind is the type for mounting host dir
813
TypeBind Type = "bind"
9-
// TypeVolume VOLUME
14+
// TypeVolume is the type for remote storage volumes
1015
TypeVolume Type = "volume"
16+
// TypeTmpfs is the type for mounting tmpfs
17+
TypeTmpfs Type = "tmpfs"
1118
)
1219

1320
// Mount represents a mount (volume).
1421
type Mount struct {
15-
Type Type `json:",omitempty"`
22+
Type Type `json:",omitempty"`
23+
// Source specifies the name of the mount. Depending on mount type, this
24+
// may be a volume name or a host path, or even ignored.
25+
// Source is not supported for tmpfs (must be an empty value)
1626
Source string `json:",omitempty"`
1727
Target string `json:",omitempty"`
1828
ReadOnly bool `json:",omitempty"`
1929

2030
BindOptions *BindOptions `json:",omitempty"`
2131
VolumeOptions *VolumeOptions `json:",omitempty"`
32+
TmpfsOptions *TmpfsOptions `json:",omitempty"`
2233
}
2334

2435
// Propagation represents the propagation of a mount.
@@ -56,3 +67,37 @@ type Driver struct {
5667
Name string `json:",omitempty"`
5768
Options map[string]string `json:",omitempty"`
5869
}
70+
71+
// TmpfsOptions defines options specific to mounts of type "tmpfs".
72+
type TmpfsOptions struct {
73+
// Size sets the size of the tmpfs, in bytes.
74+
//
75+
// This will be converted to an operating system specific value
76+
// depending on the host. For example, on linux, it will be convered to
77+
// use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with
78+
// docker, uses a straight byte value.
79+
//
80+
// Percentages are not supported.
81+
SizeBytes int64 `json:",omitempty"`
82+
// Mode of the tmpfs upon creation
83+
Mode os.FileMode `json:",omitempty"`
84+
85+
// TODO(stevvooe): There are several more tmpfs flags, specified in the
86+
// daemon, that are accepted. Only the most basic are added for now.
87+
//
88+
// From docker/docker/pkg/mount/flags.go:
89+
//
90+
// var validFlags = map[string]bool{
91+
// "": true,
92+
// "size": true, X
93+
// "mode": true, X
94+
// "uid": true,
95+
// "gid": true,
96+
// "nr_inodes": true,
97+
// "nr_blocks": true,
98+
// "mpol": true,
99+
// }
100+
//
101+
// Some of these may be straightforward to add, but others, such as
102+
// uid/gid have implications in a clustered system.
103+
}

container/container_unix.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/Sirupsen/logrus"
1414
containertypes "github.com/docker/docker/api/types/container"
15+
mounttypes "github.com/docker/docker/api/types/mount"
1516
"github.com/docker/docker/pkg/chrootarchive"
1617
"github.com/docker/docker/pkg/stringid"
1718
"github.com/docker/docker/pkg/symlink"
@@ -406,7 +407,7 @@ func copyOwnership(source, destination string) error {
406407
}
407408

408409
// TmpfsMounts returns the list of tmpfs mounts
409-
func (container *Container) TmpfsMounts() []Mount {
410+
func (container *Container) TmpfsMounts() ([]Mount, error) {
410411
var mounts []Mount
411412
for dest, data := range container.HostConfig.Tmpfs {
412413
mounts = append(mounts, Mount{
@@ -415,7 +416,20 @@ func (container *Container) TmpfsMounts() []Mount {
415416
Data: data,
416417
})
417418
}
418-
return mounts
419+
for dest, mnt := range container.MountPoints {
420+
if mnt.Type == mounttypes.TypeTmpfs {
421+
data, err := volume.ConvertTmpfsOptions(mnt.Spec.TmpfsOptions)
422+
if err != nil {
423+
return nil, err
424+
}
425+
mounts = append(mounts, Mount{
426+
Source: "tmpfs",
427+
Destination: dest,
428+
Data: data,
429+
})
430+
}
431+
}
432+
return mounts, nil
419433
}
420434

421435
// cleanResourcePath cleans a resource path and prepares to combine with mnt path

container/container_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ func (container *Container) UnmountVolumes(forceSyscall bool, volumeEventLog fun
8282
}
8383

8484
// TmpfsMounts returns the list of tmpfs mounts
85-
func (container *Container) TmpfsMounts() []Mount {
85+
func (container *Container) TmpfsMounts() ([]Mount, error) {
8686
var mounts []Mount
87-
return mounts
87+
return mounts, nil
8888
}
8989

9090
// UpdateContainer updates configuration of a container

daemon/oci_linux.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func setMounts(daemon *Daemon, s *specs.Spec, c *container.Container, mounts []c
473473
}
474474

475475
if m.Source == "tmpfs" {
476-
data := c.HostConfig.Tmpfs[m.Destination]
476+
data := m.Data
477477
options := []string{"noexec", "nosuid", "nodev", string(volume.DefaultPropagationMode)}
478478
if data != "" {
479479
options = append(options, strings.Split(data, ",")...)
@@ -707,7 +707,11 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
707707
return nil, err
708708
}
709709
ms = append(ms, c.IpcMounts()...)
710-
ms = append(ms, c.TmpfsMounts()...)
710+
tmpfsMounts, err := c.TmpfsMounts()
711+
if err != nil {
712+
return nil, err
713+
}
714+
ms = append(ms, tmpfsMounts...)
711715
sort.Sort(mounts(ms))
712716
if err := setMounts(daemon, &s, c, ms); err != nil {
713717
return nil, fmt.Errorf("linux mounts: %v", err)

daemon/volumes_unix.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
2424
var mounts []container.Mount
2525
// TODO: tmpfs mounts should be part of Mountpoints
2626
tmpfsMounts := make(map[string]bool)
27-
for _, m := range c.TmpfsMounts() {
27+
tmpfsMountInfo, err := c.TmpfsMounts()
28+
if err != nil {
29+
return nil, err
30+
}
31+
for _, m := range tmpfsMountInfo {
2832
tmpfsMounts[m.Destination] = true
2933
}
3034
for _, m := range c.MountPoints {

docs/reference/api/docker_remote_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ This section lists each version from latest to oldest. Each listing includes a
139139
* `DELETE /volumes/(name)` now accepts a `force` query parameter to force removal of volumes that were already removed out of band by the volume driver plugin.
140140
* `POST /containers/create/` and `POST /containers/(name)/update` now validates restart policies.
141141
* `POST /containers/create` now validates IPAMConfig in NetworkingConfig, and returns error for invalid IPv4 and IPv6 addresses (`--ip` and `--ip6` in `docker create/run`).
142-
* `POST /containers/create` now takes a `Mounts` field in `HostConfig` which replaces `Binds` and `Volumes`. *note*: `Binds` and `Volumes` are still available but are exclusive with `Mounts`
142+
* `POST /containers/create` now takes a `Mounts` field in `HostConfig` which replaces `Binds`, `Volumes`, and `Tmpfs`. *note*: `Binds`, `Volumes`, and `Tmpfs` are still available and can be combined with `Mounts`.
143143
* `POST /build` now performs a preliminary validation of the `Dockerfile` before starting the build, and returns an error if the syntax is incorrect. Note that this change is _unversioned_ and applied to all API versions.
144144
* `POST /build` accepts `cachefrom` parameter to specify images used for build cache.
145145
* `GET /networks/` endpoint now correctly returns a list of *all* networks,

docs/reference/api/docker_remote_api_v1.25.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,11 @@ Create a container
511511
- **Mounts** – Specification for mounts to be added to the container.
512512
- **Target** – Container path.
513513
- **Source** – Mount source (e.g. a volume name, a host path).
514-
- **Type** – The mount type (`bind`, or `volume`).
514+
- **Type** – The mount type (`bind`, `volume`, or `tmpfs`).
515515
Available types (for the `Type` field):
516516
- **bind** - Mounts a file or directory from the host into the container. Must exist prior to creating the container.
517517
- **volume** - Creates a volume with the given name and options (or uses a pre-existing volume with the same name and options). These are **not** removed when the container is removed.
518+
- **tmpfs** - Create a tmpfs with the given options. The mount source cannot be specified for tmpfs.
518519
- **ReadOnly** – A boolean indicating whether the mount should be read-only.
519520
- **BindOptions** - Optional configuration for the `bind` type.
520521
- **Propagation** – A propagation mode with the value `[r]private`, `[r]shared`, or `[r]slave`.
@@ -525,6 +526,9 @@ Create a container
525526
- **DriverConfig** – Map of driver-specific options.
526527
- **Name** - Name of the driver to use to create the volume.
527528
- **Options** - key/value map of driver specific options.
529+
- **TmpfsOptions** – Optional configuration for the `tmpfs` type.
530+
- **SizeBytes** – The size for the tmpfs mount in bytes.
531+
- **Mode** – The permission mode for the tmpfs mount in an integer.
528532

529533

530534
**Query parameters**:

0 commit comments

Comments
 (0)