Skip to content

Docker does not respect "run --memory" option #1054

@mukuntharajaa

Description

@mukuntharajaa
  • This is a bug report
  • This is a feature request
  • I searched existing issues before opening this one

Expected behavior

Docker should respect "--memory" option passed while starting the container with "run" option.

Actual behavior

Does not respect

Steps to reproduce the behavior

  1. start a container with option as, docker run --memory "256m"
  2. Run any application which will consume beyond 256mb.

Output of docker version:

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 01:27:05 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b7f0
  Built:            Wed Mar 11 01:25:01 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker info:


Client:
 Debug Mode: false

Server:
 Containers: 8
  Running: 0
  Paused: 0
  Stopped: 8
 Images: 38
 **Server Version: 19.03.8**
 Storage Driver: overlay2
  Backing Filesystem: <unknown>
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.6.8-200.fc31.x86_64
 Operating System: Fedora 31 (Workstation Edition)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.65GiB
 Name: localhost.localdomain
 ID: 27VS:EYJ5:S27F:YY3G:5QOP:CHDE:N6NS:EH5J:BZH2:AQDS:JU3M:D4ZJ
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: <--stripped off manually-->
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.)

I use following commands to build Docker image.
Complete source code available here.

  1. docker build -t alpine-limits:latest .

  2. docker run -it --rm --memory "256m" --memory-swap "256m" --name alpine-limits alpine-limits:latest sh

  3. Check limits:
    / # cat /sys/fs/cgroup/memory/memory.limit_in_bytes
    268435456

  4. Run any stress program or attached "memeater" program to consume beyond 256 MB.
    Example output of my memeater application. ( simple consumes memory via malloc in a loop of 10 iterations, consuming 100M everyloop. So in total 1 GB consumption)

 # ./memeater 
No arguments. This program consumes 100M for n rounds. Default value of n is 10. 
RLIMIT_AS: -1 -1
Going to consume 104857600
Successfully consumed 104857600 
Going to consume 209715200 
Successfully consumed 209715200 
[...]
Going to consume 1048576000 
Successfully consumed 1048576000 

Expected: Process exit due to OOM
Actual: Able to consume memory even upto 1 GB

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions