containerd/containerd · error
ErrNoShmMount
ErrNoShmMount
Error message
no /dev/shm mount specified
What it means
ErrNoShmMount is returned by opts like WithDevShmSize/WithDevShm when the generated Spec has no mount at /dev/shm for them to configure. These opts mutate the existing shm mount entry; without one there is nothing to act on.
Source
Thrown at pkg/oci/spec_opts.go:1565
if err != nil {
return err
}
defer f.Close()
sc := bufio.NewScanner(f)
for sc.Scan() {
vars = append(vars, sc.Text())
}
if err = sc.Err(); err != nil {
return err
}
return WithEnv(vars)(nil, nil, nil, s)
}
}
// ErrNoShmMount is returned when there is no /dev/shm mount specified in the config
// and an Opts was trying to set a configuration value on the mount.
var ErrNoShmMount = errors.New("no /dev/shm mount specified")
// WithDevShmSize sets the size of the /dev/shm mount for the container.
//
// The size value is specified in kb, kilobytes.
func WithDevShmSize(kb int64) SpecOpts {
return func(ctx context.Context, _ Client, _ *containers.Container, s *Spec) error {
for i, m := range s.Mounts {
if filepath.Clean(m.Destination) == "/dev/shm" && m.Source == "shm" && m.Type == "tmpfs" {
for i := 0; i < len(m.Options); i++ {
if strings.HasPrefix(m.Options[i], "size=") {
m.Options = append(m.Options[:i], m.Options[i+1:]...)
i--
}
}
s.Mounts[i].Options = append(m.Options, fmt.Sprintf("size=%dk", kb))
return nil
}
}View on GitHub (pinned to 4246446a2b)
Solutions
- Add the shm mount before sizing it, e.g. ensure Spec.Mounts includes {Type: "shm", Source: "shm", Destination: "/dev/shm"}.
- Use oci.WithDevShm (which adds the mount) before/instead of only WithDevShmSize.
- Match with errors.Is(err, oci.ErrNoShmMount) and skip shm configuration for specs that legitimately have none.
Example fix
// before
opts := []oci.SpecOpts{oci.WithDevShmSize(65536)}
// after
opts := []oci.SpecOpts{oci.WithDevShm(65536)} // adds + sizes the /dev/shm mount Defensive patterns
Strategy: try-catch
Validate before calling
hasShm := false
for _, m := range spec.Mounts {
if filepath.Clean(m.Destination) == "/dev/shm" { hasShm = true }
}
if !hasShm { /* add shm mount before applying WithDevShmSize */ } Try / catch
if err := oci.WithDevShmSize(65536)(ctx, client, &ctr, &spec); err != nil {
if errors.Is(err, oci.ErrNoShmMount) { /* add mount or skip */ }
} Prevention
- Use oci.WithDevShm to add the mount before sizing it
- When building specs by hand, include the standard /dev/shm mount
- Check spec.Mounts for /dev/shm in a pre-flight validator
When it happens
Trigger: Calling oci.WithDevShmSize(kb) (or WithDevShm) as a SpecOpt when the Spec's Mounts slice contains no mount whose destination is /dev/shm.
Common situations: Custom Spec built by hand without the default /dev/shm mount; opts applied in the wrong order so no shm mount was added yet; running on configs derived from non-Linux templates.
Related errors
- failed to activate mounts: %w
- no arguments specified
- spec does not contain Linux or Windows section
- rootfs absolute path is required
- ErrNoUsersFound
AI-assisted analysis of containerd/containerd@4246446a2b (2026-09-02).
Data as JSON: /api/errors/6ca8e308fa07e93e.
Report an issue: GitHub.