All Products
Search
Document Center

Elastic Container Instance:Mount an emptyDir volume to change the shm size

Last Updated:Dec 18, 2025

This topic describes how to resolve insufficient shared memory issues in an Elastic Container Instance (ECI) Pod. You can increase the shm size by setting the sizeLimit of a memory-type emptyDir volume and mounting it to /dev/shm.

Use cases

By default, Kubernetes allocates 64 MiB of shared memory to each Pod, which sets the size of the /dev/shm directory to 64 MiB. Kubernetes configurations do not allow you to change this size

Modify shm1

To work around this limitation, you can increase the shm size by mounting a memory-type emptyDir volume to /dev/shm.

Configuration example

  1. Create a YAML file.

    vim emptydir-shm.yaml

    The following example shows the content of the emptydir-shm.yaml file. This configuration increases the pod's shm size to 256 MiB by mounting a memory-type emptyDir volume with a 256MiB sizeLimit to the /dev/shm directory.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test
      labels:
        app: test
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          name: nginx-test
          labels:
            app: nginx
            alibabacloud.com/eci: "true" 
        spec:
          containers:
          - name: nginx
            image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
            ports:
            - containerPort: 80
            volumeMounts:
            - mountPath: /dev/shm
              name: cache-volume
          volumes:
          - emptyDir:
              medium: Memory
              sizeLimit: 256MiB
            name: cache-volume
  2. Create the Deployment.

    kubectl create -f emptydir-shm.yaml
  3. View the results.

    Log on to the container and run the df -h command to check the disk space. The output confirms that the size of /dev/shm is now 256 MiB.

    Modify the size of the shm