File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -13,12 +13,24 @@ for f in /data/gogs/data /data/gogs/conf /data/gogs/log /data/git /data/ssh; do
13
13
done
14
14
15
15
# Bind linked docker container to localhost socket using socat
16
- env | sed -En ' s|(.*)_PORT_([0-9]*)_TCP=tcp://(.*):(.*)|\1_\2 socat -ls TCP4-LISTEN:\2,fork,reuseaddr TCP4:\3:\4|p' | \
17
- while read NAME CMD; do
18
- mkdir -p /app/gogs/docker/s6/SOCAT_$NAME
19
- echo -e " #!/bin/sh\nexec $CMD " > /app/gogs/docker/s6/SOCAT_$NAME /run
20
- chmod +x /app/gogs/docker/s6/SOCAT_$NAME /run
21
- done
16
+ USED_PORT=" 3000:22"
17
+ while read NAME ADDR PORT; do
18
+ if test -z " $NAME$ADDR$PORT " ; then
19
+ continue
20
+ elif echo $USED_PORT | grep -E " (^|:)$PORT ($|:)" > /dev/null; then
21
+ echo " init:socat | Can't bind linked container ${NAME} to localhost, port ${PORT} already in use" 1>&2
22
+ else
23
+ SERV_FOLDER=/app/gogs/docker/s6/SOCAT_${NAME} _${PORT}
24
+ mkdir -p ${SERV_FOLDER}
25
+ CMD=" socat -ls TCP4-LISTEN:${PORT} ,fork,reuseaddr TCP4:${ADDR} :${PORT} "
26
+ echo -e " #!/bin/sh\nexec $CMD " > ${SERV_FOLDER} /run
27
+ chmod +x ${SERV_FOLDER} /run
28
+ USED_PORT=" ${USED_PORT} :${PORT} "
29
+ echo " init:socat | Linked container ${NAME} will be binded to localhost on port ${PORT} " 1>&2
30
+ fi
31
+ done << EOT
32
+ $( env | sed -En ' s|(.*)_PORT_([0-9]+)_TCP=tcp://(.*):([0-9]+)|\1 \3 \4|p' )
33
+ EOT
22
34
23
35
# Exec CMD or S6 by default if nothing present
24
36
if [ $# -gt 0 ]; then
You can’t perform that action at this time.
0 commit comments