#!/bin/bash if [ -z $1 ]; then echo "Usage: c run <p_w_picpath 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="80" 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 ..." 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
Docker容器重启脚本
原创
©著作权归作者所有:来自51CTO博客作者蜗牛奔跑ing的原创作品,谢绝转载,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
01-docker技术概述、容器管理命令、镜像管理命令
docker管理命令、容器管理命令
docker kylin linux -
重启docker容器命令
先查看docker容器docker ps -a然后用docker attach 命令进入启动的docker
dockerhub docker -
docker重启容器命令docker
-
docker容器自动重启命令
linux dockee和服务自启动
docker 重启 自动重启