Skip to content

Instantly share code, notes, and snippets.

@diablowu
Created March 10, 2015 01:32
Show Gist options
  • Select an option

  • Save diablowu/7c81538aa1c28fe8c363 to your computer and use it in GitHub Desktop.

Select an option

Save diablowu/7c81538aa1c28fe8c363 to your computer and use it in GitHub Desktop.
start a container of tomcat images
#!/bin/bash
warfile=$1
#dockerman path
dmdir=`pwd`
hostip='10.0.22.151'
#make a boxid
boxid=`</dev/urandom tr -dc 'a-z0-9'|fold -w 32|head -n1`
datadir="/data/$boxid"
#create container work dir
mkdir -p $datadir
cd $datadir
mkdir {webapps,logs}
'cp' $warfile ${datadir}/webapps
cntid=`docker run -d --user=www --name=$boxid -v ${datadir}/webapps:/data/webapps -v ${datadir}/logs:/data/logs tomcat_box:1.1.3 /home/www/run.sh`
cntip=`docker inspect --format='{{.NetworkSettings.IPAddress}}' $cntid`
cd $dmdir
lastport=`tail -n1 port.txt`
currport=`expr $lastport \+ 1`
echo $currport >> port.txt
./addnat.sh $cntip 8080 $hostip $currport
echo -e "container_id \t box_id \t listened \t"
echo -e "$cntid \t $boxid \t ${hostip}(${cntip}):${currport} \t"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment