How to limit amount of running docker instances?

I am using one machine to host docker and launch containers on demand for other machines. However my resources are not unlimited and machines making those requests don’t have any knowledge about other requests. I’d like to limit the amount of containers that my docker host can launch to a certain amount. How can I achieve that?

  • How to allocate 50% CPU resource to docker container?
  • Docker Error: CSS File in Mapped Volume Fails to Update
  • Commands in Docker ENTRYPOINT
  • Pulling image from Amazon ECR using docker-java
  • Docker container CPU and Memory Utilization
  • build a data container or point to the existing files in docker?
  • Mount volume to Docker image on OSX
  • Overlay network aware HAProxy
  • Should I run the init process inside a Docker container or not? [closed]
  • I found an image on docker hub that I like but doesn't meet my needs. How do I update it and make it my own?
  • Pushing files into private registry in Docker
  • How can I pull the official images of IBM Container Service?
  • One Solution collect form web for “How to limit amount of running docker instances?”

    The only way I know is to write a or monitor which implements your business rules.

    That is, something that either:

    1. intercepts the calls to the docker daemon and only lets a certain amount of RAM or number of processes start, OR
    2. a separate daemon that listens to docker daemon events and kills containers when there are too many.

    There might also be some hook in the kernel to place limits on the number of cgroups/namespaces created, but I don’t know the calls offhand.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.