title: Limit useable host resources in Docker compose without swarm
body: <p>I simply want to limit the resources of some Docker containers in a docker-compose file. The reason is simple: There are multiple apps/services running on the host. So I want to avoid, that a single container can use e.g. all memory, which harms the other containers. </p>
  
  <p>From the docs I learned, that this can be done using <code>resources</code>. But this is beyond <code>deploy</code>. So I have to write my docker-compose file like the following example: </p>
  
  <pre><code>  php:
      image: php:7-fpm
      restart: always
      volumes:
        - ./www:/www
      deploy:
        resources:
          limits:
            memory: 512M
  </code></pre>
  
  <p>This gave me the warning: </p>
  
  <blockquote>
    <p>WARNING: Some services (php) use the 'deploy' key, which will be ignored. Compose does not support deploy configuration - use <code>docker stack deploy</code> to deploy to a swarm.</p>
  </blockquote>
  
  <p>And that seems to be true: <code>docker stats</code>confirms, the container is able to use all the ram from the host. </p>
  
  <p>The documentation says: </p>
  
  <blockquote>
    <p>Specify configuration related to the deployment and running of services. This only takes effect when deploying to a swarm with docker stack deploy, and is ignored by docker-compose up and docker-compose run.</p>
  </blockquote>
  
  <p>But I don't need clustering. It seems that there is no other way to limit resources using a docker composer file. Why is it not possible to specify some kind of <code>memory</code>tag like the start-parameter in <code>docker run</code>does? </p>
  
  <p>Example: <code>docker run --memory=1g $imageName</code></p>
  
  <p>This works perfectly for a single container. But I can't use this (at least without violating a clean separation of concerns), since I need to use two different containers. </p>
  
  <h3>Edit: Temp workaround</h3>
  
  <p>I found out, that I'm able to use <code>mem_limit</code> directly after downgrading from version 3 to version 2 (placing <code>version: '2'</code> on top). But we're currently on version 3.1, so this is not a long-time solution. And the docs say, that <code>deploy.resources</code> is the new replacement for v2 tags like <code>mem_limit</code>. </p>
  
  <p>Someday, version 2 is deprecated. So resource management isn't possible any more with the latest versions, at least without having a swarm? Seems a worsening for me, can't belive this... </p>