Search code examples
dockerdocker-swarm

Updating docker containers on swarm?


How does docker swarm (1.12+) works with container updates? Example:

On one node I have 2 containers, both uses 4GB of memory, total is 8 GB, which is equals to node size.

What if I change memory size of one container to e.g. 6 GB? Will swarm :

  • reschedule container to new node that has 6 GB free?
  • fail to update?
  • keeps working both containers as before?

I am failing to figure out by myself.


Solution

  • Assuming you're using services on the Swarm and explicitly reserving memory per container, your service will stick in the 'allocated' state if you try to update it to reserve more memory than you have available.

    E.g: docker service create --replicas 1 --name nginx --reserve-memory 256M nginx will succeed and create 1 container with 256MB reserved for it (if you have capacity on your Swarm). Then run docker service update --reserve-memory 300G nginx and Docker will:

    1. Shutdown the existing container
    2. Try to schedule a new container with the requested resources

    If you don't have a node with 300GB available, the updated service can't be scheduled and it will sit in the Allocated state, so your service won't be running at this point.

    The scheduler keeps checking, so if the resources do become available, or if you run a new update command with a lower reserve, then it will create the container as requested.