diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 87f801c1549c..8e1c8b6ec8e3 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -731,13 +731,20 @@ stop() { if [[ "$DEV" && $DATABASE_TYPE != "dpudb" ]]; then ip netns delete "$NET_NS" fi - {%- elif docker_container_name == "teamd" %} - # Longer timeout of 60 sec to wait for Portchannels to be cleaned. - /usr/local/bin/container stop -t 60 $DOCKERNAME + {%- else %} + container_id=$(docker ps --filter "name=$DOCKERNAME" --quiet) + if [ -z "$container_id" ]; then + echo "container stop $DOCKERNAME - No such container: $DOCKERNAME" + else + {%- if docker_container_name == "teamd" %} + # Longer timeout of 60 sec to wait for Portchannels to be cleaned. + /usr/local/bin/container stop -t 60 $DOCKERNAME {%- elif docker_container_name in ["swss", "syncd"] and enable_asan == "y" %} - /usr/local/bin/container stop -t 60 $DOCKERNAME + /usr/local/bin/container stop -t 60 $DOCKERNAME {%- else %} - /usr/local/bin/container stop $DOCKERNAME + /usr/local/bin/container stop $DOCKERNAME + {%- endif %} + fi {%- endif %} }