• 7

I have application working as set of microservicies. Each microservice is running in separate docker container. I'm looking for method to set the maximum allowable memory, which each container can use. For now I've 12 of them, which drains all of 16GB RAM. Sometimes this make working on console a little bit difficult, because of lags.

I'm starting containers using command like this one

docker run -d -p 8093:8080 --env-file ./saturno-environment-files/edge-server.list --name edge-server acisa/edge-server --memory=1g

I see in docker inspect -container- that this command is recognized properly

root@PlatformServer:/sys/fs/cgroup/memory/system.slice# docker inspect edge-server [{ "AppArmorProfile": "", "Args": [ "-Djava.security.egd=file:/dev/./urandom", "-Dspring.profiles.active=${PROFILE_ACTIVE}", "-jar", "/app.jar", "--memory=1g" ], "Config": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "--memory=1g" ], But unfortunately containers still fill memory up to 80~95%. In docker stats I see that memory limit is still 15.68GiB (physical RAM in server), and what makes me curious MEM USAGE is reported as 0B. CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O edge-server 0.00% 0 B/15.68 GiB 0.00% 13.65 MiB/38.12 MiB

      • 1
    • Have you tried passing the memory allocation to docker, rather than to whatever is running inside the container? In other words, move the --memory 1g clause, for example, between your -d and -p flags.

Everything you pass after the image name becomes the CMD value for your container, and when you have an entrypoint defined, the cmd becomes args at the end of the entrypoint. So with the command you provided:

  • docker run: docker client with the run option
  • -d: detached
  • -p 8093:8080: expose container port 8080 to host port 8093
  • --env-file ./saturno-environment-files/edge-server.list: use this file to pass env variables
  • --name edge-server: name the container
  • acisa/edge-server: first thing that isn't a flag to docker run, this is your image name and ends the args to docker run
  • --memory=1g: cmd that is passed as arguments to the image entrypoint

To fix this, you just need to reorder the cli options:

docker run -d -p 8093:8080 --env-file ./saturno-environment-files/edge-server.list --name edge-server --memory=1g acisa/edge-server

Note that the memory quota features may also depend on a newer kernel and that your install of docker is extremely out of date.

  • 0
Reply Report
    • Hello,Thank You for assistance. This was stupid mistake, but now memory limiting it is working :) Unfortunately swap not at all :( When I'm starting docker I see message like "parameter was rejected due to too old kernel". In host I've 4.7.0-0.bpo.1-amd64 so I assume I must upgrade docker itself?
      • 1
    • A 4.x kernel is more than current enough. I would recommend upgrading the docker version before trying to debug anything else. I would get to at least a 17.03 install if you're on the community (open source) edition.

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags