Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM --platform=linux/amd64 debian:bullseye-slim

RUN apt-get update
RUN apt-get install -y unzip wget x11vnc xvfb socat nano
RUN apt-get install -y unzip wget x11vnc xvfb socat net-tools nano

WORKDIR /root

Expand Down Expand Up @@ -37,11 +37,19 @@ RUN cp /opt/ibc/config.ini ./ibc/
RUN chmod a+x run_ibc.sh

#Environment variables and ports
ENV IB_PORT 4000
ENV GW_LIVE_PORT 4001
ENV GW_PAPER_PORT 4002
ENV TWS_LIVE_PORT 7496
ENV TWS_PAPER_PORT 7497
ENV DISPLAY :0
ENV TWS_PORT 4002
ENV VNC_PORT 5900
EXPOSE $TWS_PORT

EXPOSE $IB_PORT
EXPOSE $VNC_PORT

#Enable healthcheck
HEALTHCHECK CMD netstat -ltn | grep -c ":$GW_LIVE_PORT\|:$GW_PAPER_PORT\|:$TWS_LIVE_PORT\|:$TWS_PAPER_PORT"

#Run IBC
CMD ./run_ibc.sh
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ Or run directly with `docker run` command:
## Connection
Use container address and port **4002** to connect to the IB application.

## Healthcheck
The `netstat` utility is included and used to check IB socket port. You can customize healthcheck parameters and have the container automatically restart on unhealthy status. Please read about [autoheal](https://github.com/willfarrell/docker-autoheal) and see example `docker-compose.yml`.

## Disclaimer
This method of deploying TWS/Gateway is not endorsed nor supported by Interactive Brokers.
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
version: '3.9'

services:
autoheal:
container_name: autoheal
image: willfarrell/autoheal
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock

ib:
container_name: ib
image: zdytch/ib-dockerized
Expand All @@ -16,3 +23,9 @@ services:
- ./config.ini:/root/ibc/config.ini
ports:
- 5900:5900
labels:
autoheal: "true"
healthcheck:
interval: 15s
timeout: 5s
retries: 4
39 changes: 28 additions & 11 deletions run_ibc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,41 @@ rm -f /tmp/.X0-lock
Xvfb :0 &
sleep 1


#Prepare arguments and port for Gateway or TWS
APP_ARGS="--mode=$IB_MODE --user=$IB_USER --pw=$IB_PASSWORD"
INT_PORT=0

if [ $IB_APP = "gw" ] ; then
APP_ARGS="$(ls ~/Jts/ibgateway) --gateway $APP_ARGS"

if [ $IB_MODE = "live" ] ; then
INT_PORT=$GW_LIVE_PORT
elif [ $IB_MODE = "paper" ] ; then
INT_PORT=$GW_PAPER_PORT
fi

elif [ $IB_APP = "tws" ] ; then
APP_ARGS="$(ls ~/Jts | head -1) $APP_ARGS"

if [ $IB_MODE = "live" ] ; then
INT_PORT=$TWS_LIVE_PORT
elif [ $IB_MODE = "paper" ] ; then
INT_PORT=$TWS_PAPER_PORT
fi
fi


#Run VNC if password is set
if [ $VNC_PASSWORD ] ; then
mkdir -p .vnc
x11vnc -storepasswd $VNC_PASSWORD .vnc/passwd
x11vnc -rfbport $VNC_PORT -display :0 -usepw -forever &
fi

#Forward TWS port from to 4001, to simulate local connection
socat TCP-LISTEN:$TWS_PORT,fork TCP:localhost:4001,forever &

#Prepare arguments for Gateway or TWS
APP_ARGS="--mode=$IB_MODE --user=$IB_USER --pw=$IB_PASSWORD"
if [ $IB_APP = "gw" ]
then
APP_ARGS="$(ls ~/Jts/ibgateway) --gateway $APP_ARGS"
elif [ $IB_APP = "tws" ]
then
APP_ARGS="$(ls ~/Jts | head -1) $APP_ARGS"
fi
#Forward IB port from internal to external, to simulate local connection
socat TCP-LISTEN:$IB_PORT,fork TCP:localhost:$INT_PORT,forever &


/opt/ibc/scripts/ibcstart.sh $APP_ARGS