Skip to content

Commit 5cd10c3

Browse files
committed
Added support for running different containers mapping internal port 8000 to different external ports. Added additional text explaining why we won't run multiple containers from the same svn branch. Did som default value code refactoring.
- Legacy-Id: 10471
1 parent 99d6ce5 commit 5cd10c3

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

docker/run

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)";
7474
# Option parsing
7575

7676
# Options
77-
shortopts=dhi:m:Mr:t:vVu:
78-
longopts=download-data,help,ietfdb-url=,mysqldata=,no-mysqldir,docker-repo=,tag=,verbose,version,user=,
77+
shortopts=dhi:m:Mp:r:t:vVu:
78+
longopts=download-data,help,ietfdb-url=,mysqldata=,no-mysqldir,port=,docker-repo=,tag=,verbose,version,user=,
7979

8080
# Default values
81-
TAG=$(basename $(svn info $parent | grep ^URL | awk '{print $2}'))
82-
REPO="levkowetz/datatracker"
81+
MYSQLDIR=$parent/data/mysql
8382
NOMYMAP=""
83+
PORT=8000
84+
REPO="levkowetz/datatracker"
85+
TAG=$(basename $(svn info $parent | grep ^URL | awk '{print $2}'))
86+
URL=https://www.ietf.org/lib/dt/sprint/ietf_utf8.bin.tar.bz2
87+
WHO=$(whoami)
8488

8589
if [ "$(uname)" = "Linux" ]; then
8690
args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@")
@@ -101,7 +105,8 @@ while true ; do
101105
-h| --help) usage; exit;; # Show this help, then exit
102106
-i| --ietfdb-url) URL=$2; shift;; # Use an alternative database tarball URL
103107
-m| --mysqldir) MYSQLDIR=$2; shift;; # Set the desired location for MySQL's database files
104-
-M| --no-mysqldir) NOMYMAP=1;; # Don't map the mysql dir to an external dir
108+
-M| --no-mysqldir) NOMYMAP=1;; # Don't map the mysql dir to an external dir
109+
-p| --port) PORT=$2; shift;; # Bind the container's port 8000 to external port PORT
105110
-r| --docker-repo) REPO=$2; shift;; # Use the given docker repository, instead of the default
106111
-t| --tag) TAG=$2; shift;; # Use this docker image tag, instead of the svn branch name
107112
-u| --user) WHO=$2; shift;; # Run the container as the specified user
@@ -148,12 +153,11 @@ echo "Starting a docker container for '$TAG'."
148153

149154
docker ps | grep -q $REPO:$TAG && die \
150155
"It seems that another docker container is already running the
151-
image '$REPO:$TAG' -- but only one MySQL instance can bind
152-
to the database files at a time. Quitting."
153-
154-
[ -n "$WHO" ] || WHO=$(whoami)
155-
[ -n "$MYSQLDIR" ] || MYSQLDIR=$parent/data/mysql
156-
[ -n "$URL"] || URL=https://www.ietf.org/lib/dt/sprint/ietf_utf8.bin.tar.bz2
156+
image '$REPO:$TAG'. Continuing here can cause various problems,
157+
such as changes from within the container being saved from different
158+
containers to the same image, overwriting earlier changes, and
159+
multiple containers trying to use the same database files. Better
160+
to bail out here. Quitting."
157161

158162
if [ -n "$DOWNLOAD" ]; then
159163
(
@@ -176,9 +180,9 @@ if ! docker images $REPO | grep -q $TAG; then
176180
fi
177181

178182
if [ -n "$NOMYMAP" ]; then
179-
docker run -ti -p 8000:8000 -v $HOME:/home/$WHO -e USER=$WHO -e DATADIR=${parent#$HOME/}/data -e CWD=${PWD#$HOME/} -e TAG=$TAG $REPO:$TAG
183+
docker run -ti -p 8000:$PORT -v $HOME:/home/$WHO -e USER=$WHO -e DATADIR=${parent#$HOME/}/data -e CWD=${PWD#$HOME/} -e TAG=$TAG $REPO:$TAG
180184
else
181-
docker run -ti -p 8000:8000 -v $HOME:/home/$WHO -v $MYSQLDIR:/var/lib/mysql -e USER=$WHO -e DATADIR=${parent#$HOME/}/data -e CWD=${PWD#$HOME/} -e TAG=$TAG $REPO:$TAG
185+
docker run -ti -p 8000:$PORT -v $HOME:/home/$WHO -v $MYSQLDIR:/var/lib/mysql -e USER=$WHO -e DATADIR=${parent#$HOME/}/data -e CWD=${PWD#$HOME/} -e TAG=$TAG $REPO:$TAG
182186
fi
183187

184188
echo ""

0 commit comments

Comments
 (0)