IB@stoqey/ib
@stoqey/ib (Low-Level SDK)Guides & Resources

Headless IB Gateway Docker Setup

Setting up headless IB Gateway using Docker and docker-compose for continuous cloud deployment.

Why Headless IB Gateway?

Running Interactive Brokers Gateway in Docker provides an isolated, headless environment that doesn't require GUI displays or manual interaction on cloud servers (AWS EC2, GCP, DigitalOcean, Hetzner, Docker Swarm, Kubernetes).


docker-compose.yml Configuration

Add the following docker-compose.yml configuration:

version: "3.8"

services:
  ib-gateway:
    image: ghcr.io/stoqey/ib-gateway:latest
    container_name: ib-gateway
    restart: always
    ports:
      - "4002:4002" # Paper trading socket port
      - "4001:4001" # Live trading socket port
    environment:
      - TWS_USERID=${TWS_USERID}
      - TWS_PASSWORD=${TWS_PASSWORD}
      - TRADING_MODE=${TRADING_MODE:-paper}
      - READ_ONLY_API=no
      - IB_PORT=4002

Environment Configuration (.env)

Create a .env file in the same directory:

TWS_USERID=your_ibkr_username
TWS_PASSWORD=your_ibkr_password
TRADING_MODE=paper

Launching the Container

# Start container in detached mode
docker-compose up -d

# Check container logs
docker-compose logs -f ib-gateway

Once initialized, connect your @stoqey/ib application to port 4002 (paper) or 4001 (live)!

On this page