I'm using with_sequence to iteratively create copies of a container on a single node using ansible. The number of containers is determined by a variable set at the time of deploy. This works well for increasing the number of containers to scale up, but when I reduce the number to deploy less containers the old containers are left running. Is there a way to stop the old containers? Prune won't seem to work correctly since the old containers aren't stopped.
Linked Questions
- I keep getting "bsdtar: Failed to set file flags" when I try do pull base
- Docker daemon not starting
- How to manage docker image dependencies (maintainance)
- Connect from docker container to a host port
- Scaling: Docker containers vs Vms
- Is there any way to find out who pushed an image with a specific tag to a repo on hub.docker.com?
- How can I share a network interface with docker without setns error?
- Update docker-compose on windows 10 with docker toolbox
- Exact times in "docker ps" and "docker images"
- How to idiomatically access sensitive data when building a Docker image?
- NODE doesn't show in NODE menu in shipyard
- Multiple RUN instructions vs. single CMD to execute setup script in Dockerfile to initialize container
- Unable to connect localhost in docker
- Why there are two different PID for the same process inside of docker
- How and why OS being used as containers on docker
Popular Questions
- Partially applied generic function "cannot be cast to Nothing"
- Agar.io style ripple effect for canvas arcs
- What is the difference between [ValidateModel] and a check of valid state in ASP.NET?
- Passing shared_ptr to std::function (member function)
- UWP location tracking even when the app was suspended
- Dynamic partition in hive
- Woocommerce Different Products Different Currency
- Rails render js file but can't execute it
- My rotated TextView is cut off. What i have to do?
- Store object created by gson in greenDao
1 Answers
Related Questions
- Cannot connect to the Docker daemon at unix:///var/run/docker.sock on Ubuntu 16.04
- Docker params: "run -it" and "start -i". Why not "start -it"
- Is there a way to re attach to a still opened session using the TTY with docker?
- How to look at a file in a docker image (example: Docker's 'hello-world' image)
- Geting a log of execution of current instructions when doing a 'docker run'
- Location of the local copy of Docker's registry manifest-file
- docker terminal: waiting for an IP
- Docker : How to run a service and a terminal in one command?
- Access service on host machine from docker container
- Accessing Environment Variables in a linked Docker
- docker: net: no such interface
- Can I suspend and then resume Docker container?
- How do I set resources allocated to a container using docker?
- How to list containers in Docker
- Should I be concerned about excess, non-running, Docker containers?
One option is to move from Ansible to docker-compose, which knows how to scale up and scale down (and honestly provides a better use experience for manage complex Docker configurations).
Another idea would be to include one loop for starting containers, and then a second loop that attempts to remove containers up to some maximum number, like this (assuming the number of containers you want to start is in the ansible variable
container_count
):Called with the default values defined in the playbook, it would create 4 containers and then attempt to delete 16 more. This is going to be a little slow, since Ansible doesn't provide any way to prematurely exit a loop, but it will work.
A third option is to replace the "Stop containers" task with a shell script, which might be slightly faster but less "ansible-like":
Same idea, but somewhat faster and it doesn't require you to define a maximum container count.