Docker container Restart script

Source: Internet
Author: User
Tags etcd

#!/bin/bash    if [ -z $1 ]; then  echo  "Usage:  c run <image name>:<version> "  echo "         c stop <container name> "  exit 1  fi     if [ -z  $ETCD _host ]; then  etcd_host= "192.168.2.98:4001"   fi    if [ -z  $ETCD _prefix ]; then  etcd_ prefix= "App/servers"   fi    if [ -z  $CPORT  ]; then   cport=   fi if [ -z  $FORREST _ip ]; then   Forrest_ip= ' ifconfig eth0| grep  "inet addr"  | head -1 | cut  -d : -f2 | awk  ' {print $1} '   fi function launch_container  {  echo  "Launching $1 on  $FORREST _ip&nbsp, ... " container_id= ' Docker run -d --dns  172.17.42.1 -p -v /data:/data -v /etc/httpd/conf:/etc/httpd/conf -v / Etc/httpd/conf.d:/etc/httpd/conf.d -v /etc/localtime:/etc/localtime:ro $1 /bin/sh -c   "/usr/bin/supervisord -c /etc/supervisord.conf" '   port= ' docker inspect $ container_id|grep  "\" ports\ " -A 50|grep " \ "$CPORT/tcp\" " -A 3| grep  hostport|cut -d  ' "'  -f4|head -1 '   name= ' docker inspect  $CONTAINER _id  | grep Name | cut -d  ' "'  -f4 | sed " s/\///g "|sed  -n 2p '  echo  "announcing to  $ETCD _host ..."   curl -XPUT  "http://$ etcd_host/v2/keys/$ETCD _prefix/$NAME " -d value=" $FORREST _ip: $PORT " echo " $1 running  on port $port with name  $NAME "  } function stop_container {  echo   "Stopping $1 ..."   container_id= ' docker ps -a| grep $1 | awk  ' {print $1} '   echo  "found container  $CONTAINER _id"   docker stop  $CONTAINER _id   echo http://$ETCD _host/v2/keys/$ETCD _prefix/$1  curl -xdelete http://$ etcd_host/v2/keys/$ETCD _prefix/$1 &> /dev/null  echo  "Stopped."   }                  if [ $1 =  "Run"  ]; then  launch_container $2   Else  stop_container $2  fi


This article is from the "my operation and maintenance of the road" blog, declined reprint!

Docker container Restart script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.