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 1313 shell : sudo docker rm {{ item }}
1414 with_items : stopped_containers.stdout_lines
1515
16+ # copy findTagRunning.sh
17+ - name : " copy find running containers with this image tag util script"
18+ sudo : yes
19+ copy :
20+ src=findTagRunning.sh
21+ dest=/root/findTagRunning.sh
22+ mode=0700
23+
1624# get current running container with this image
1725- name : " look for running containers running {{ container_image }}"
18- shell : " sudo docker ps | grep -v '^CONTAINER' | awk '{print $1,$2}' | grep -e {{ container_image }} -v -e ':'|awk -F' ' '{print $1}'"
26+ # shell: "sudo docker ps | grep -v '^CONTAINER' | awk '{print $1,$2}' | grep -e {{ container_image }} -v -e ':'|awk -F' ' '{print $1}'"
27+ sudo : yes
28+ shell : " /root/findTagRunning.sh {{ container_image }}"
1929 register : old_containers_id
2030 changed_when : old_containers_id.stdout != ''
2131
You can’t perform that action at this time.
0 commit comments