File tree Expand file tree Collapse file tree
ansible/roles/container_kill_start Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ IMAGE_NAME=" $1 "
4+ RUNNING_CONTAINERS=" "
5+
6+ CONTAINERS=` docker ps | grep -v ' ^CONTAINER' | awk ' {print $1}' `
7+
8+ if [ " " = " ${CONTAINERS} " ] ; then
9+ exit 0
10+ else
11+ for container in ${CONTAINERS} ; do
12+ docker inspect ${container} | grep -q ${IMAGE_NAME}
13+ if [ ${?} -eq 0 ] ; then
14+ RUNNING_CONTAINERS=" ${container} "
15+ fi
16+ done
17+ fi
18+
19+ echo " ${RUNNING_CONTAINERS} "
Original file line number Diff line number Diff line change 1- ---
21- name : " look for stopped {{ container_image }} containers"
32 shell : >
43 sudo docker ps -a |
1312 shell : sudo docker rm {{ item }}
1413 with_items : stopped_containers.stdout_lines
1514
15+ - name : " copy find running containers with this image tag util script"
16+ sudo : yes
17+ copy :
18+ src=findTagRunning.sh
19+ dest=/root/findTagRunning.sh
20+ mode=0700
21+
1622# get current running container with this image
1723- name : " look for running containers running {{ container_image }}"
18- shell : " sudo docker ps | grep {{ container_image }}: | awk '{print $1}'"
24+ sudo : yes
25+ shell : " /root/findTagRunning.sh {{ container_image }}"
1926 register : old_containers_id
2027 changed_when : old_containers_id.stdout != ''
2128
You can’t perform that action at this time.
0 commit comments