
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
A docker image to run the Interactive Brokers Gateway Application without any human interaction on a docker container.
It includes:
| Channel | IB Gateway Version | IBC Version | Docker Tags |
|---|---|---|---|
latest | 10.24.1e | 3.18.0 | latest 10.24 10.24.1e |
stable | 10.19.2d | 3.18.0 | stable 10.19 10.19.2d |
This README might not have the latest tags, but you can always get https://github.com/users/gnzsnz/packages/container/ib-gateway/***?tag=stable and https://github.com/users/gnzsnz/packages/container/ib-gateway/***?tag=latest plus all available https://github.com/gnzsnz/ib-gateway-docker/pkgs/container/ib-gateway/.
Create a docker-compose.yml (or include ib-gateway services on your existing one)
yamlversion: "3.4" services: ib-gateway: image: ghcr.io/gnzsnz/ib-gateway:latest restart: always environment: TWS_USERID: ${TWS_USERID} TWS_PASSWORD: ${TWS_PASSWORD} TRADING_MODE: ${TRADING_MODE:-live} VNC_SERVER_PASSWORD: ${VNC_SERVER_PASSWORD:-} READ_ONLY_API: ${READ_ONLY_API:-} TWOFA_TIMEOUT_ACTION: ${TWOFA_TIMEOUT_ACTION:-exit} AUTO_RESTART_TIME: ${AUTO_RESTART_TIME:-} RELOGIN_AFTER_TWOFA_TIMEOUT: ${RELOGIN_AFTER_TWOFA_TIMEOUT:-no} TWOFA_EXIT_INTERVAL: ${TWOFA_EXIT_INTERVAL:-60} TIME_ZONE: ${TIME_ZONE:-Etc/UTC} ports: - "127.0.0.1:4001:4001" - "127.0.0.1:4002:4002" - "127.0.0.1:5900:5900"
Create an .env on root directory or set the following environment variables:
| Variable | Description | Default |
|---|---|---|
TWS_USERID | The TWS username. | |
TWS_PASSWORD | The TWS password. | |
TRADING_MODE | live or paper | paper |
READ_ONLY_API | yes or no (see) | not defined |
VNC_SERVER_PASSWORD | VNC server password. If not defined, no VNC server will be started. | not defined (VNC disabled) |
TWOFA_TIMEOUT_ACTION | 'exit' or 'restart', set to 'restart if you set AUTO_RESTART_TIME. See IBC https://github.com/IbcAlpha/IBC/blob/master/userguide.md#second-factor-authentication | 'exit' |
AUTO_RESTART_TIME | time to restart IB Gateway, does not require daily 2FA validation. format hh:mm AM/PM. See IBC https://github.com/IbcAlpha/IBC/blob/master/userguide.md#ibc-user-guide | not defined |
RELOGIN_AFTER_2FA_TIMEOUT | support relogin after timeout. See IBC https://github.com/IbcAlpha/IBC/blob/master/userguide.md#second-factor-authentication | 'no' |
TIME_ZONE | Support for timezone, see your TWS jts.ini file for valid values or a tz database. This sets time zone for IB Gateway. Examples Europe/Paris, America/New_York, Asia/Tokyo | "Etc/UTC" |
Example .env file:
textTWS_USERID=myTwsAccountName TWS_PASSWORD=myTwsPassword TRADING_MODE=paper READ_ONLY_API=no VNC_SERVER_PASSWORD=myVncPassword TWOFA_TIMEOUT_ACTION=restart AUTO_RESTART_TIME=11:59 PM RELOGIN_AFTER_2FA_TIMEOUT=yes TIME_ZONE=Europe/Lisbon
Run:
$ docker-compose up
After image is downloaded, container is started + 30s, the following ports will be ready for usage on the container and docker host:
| Port | Description |
|---|---|
| 4001 | TWS API port for live accounts. |
| 4002 | TWS API port for paper accounts. |
| 5900 | When VNC_SERVER_PASSWORD was defined, the VNC server port. |
_Note that with the above docker-compose.yml, ports are only exposed to the
docker host (127.0.0.1), but not to the network of the host. To expose it to
the whole network change the port mappings on accordingly (remove the
'127.0.0.1:'). Attention: See #leaving-localhost
Clone this repo
bashgit clone https://github.com/gnzsnz/ib-gateway-docker
Change docker file to use your local IB Gateway installer file, instead of loading it from this project releases:
Open Dockerfile on editor and replace this lines:
dockerRUN curl -sSL https://github.com/gnzsnz/ib-gateway-docker/raw/gh-pages/ibgateway-releases/ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh \ --output ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh RUN curl -sSL https://github.com/gnzsnz/ib-gateway-docker/raw/gh-pages/ibgateway-releases/ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh.sha256 \ --output ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh.sha256
with
dockerCOPY ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh
Remove RUN sha256sum --check ./ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh.sha256 from Dockerfile (unless you want to keep checksum-check)
Download IB Gateway and name the file ibgateway-{IB_GATEWAY_VERSION}-standalone-linux-x64.sh, where {IB_GATEWAY_VERSION} must match the version as configured on Dockerfile (first line)
Download IBC and name the file IBCLinux-{IBC_VERSION}.zip, where {IBC_VERSION} must match the version as configured on Dockerfile (second line)
Build and run: docker-compose up --build
The docker image version is similar to the IB Gateway version on the image.
See Supported tags
Note that the https://github.com/gnzsnz/ib-gateway-docker/blob/master/Dockerfile does not download IB Gateway installer files from IB homepage but from the https://github.com/gnzsnz/ib-gateway-docker/tree/gh-pages/ibgateway-releases of this project.
This is because it shall be possible to (re-)build the image, targeting a specific Gateway version,
but IB does only provide download links for the latest or stable version (there is no 'old version' download archive).
The installer files stored on https://github.com/gnzsnz/ib-gateway-docker/tree/gh-pages/ibgateway-releases have been downloaded from IB homepage and renamed to reflect the version.
If you want to download Gateway installer from IB homepage directly, or use your local installation file, change this line
on https://github.com/gnzsnz/ib-gateway-docker/blob/master/Dockerfile
RUN curl -sSL https://github.com/gnzsnz/ib-gateway-docker/raw/gh-pages/ibgateway-releases/ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh --output ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh to download (or copy) the file from the source you prefer.
Example: change to RUN curl -sSL https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/ibgateway-stable-standalone-linux-x64.sh --output ibgateway-${IB_GATEWAY_VERSION}-standalone-linux-x64.sh for using current stable version from IB homepage.
The image can be customized by overwriting the default configuration files with custom ones.
Apps and config file locations:
| App | Folder | Config file | Default |
|---|---|---|---|
| IB Gateway | /root/Jts | /root/Jts/jts.ini | https://github.com/gnzsnz/ib-gateway-docker/blob/master/config/ibgateway/jts.ini |
| IBC | /root/ibc | /root/ibc/config.ini | https://github.com/gnzsnz/ib-gateway-docker/blob/master/config/ibc/config.ini.tmpl |
To start the IB Gateway run /root/scripts/run.sh from your Dockerfile or
run-script.
The IB API protocol is based on an unencrypted, unauthenticated, raw TCP socket connection between a client and the IB Gateway. If the port to IB API is open to the network, every device on it (including potential rogue devices) can access your IB account via the IB Gateway.
Because of this, the default docker-compose.yml only exposes the IB API port
to the localhost on the docker host, but not to the whole network.
If you want to connect to IB Gateway from a remote device, *** adding an additional layer of security (e.g. TLS/SSL or SSH tunnel) to protect the 'plain text' TCP sockets against unauthorized access or manipulation.
This image does not contain nor store any user credentials.
They are provided as environment variable during the container startup and the host is responsible to properly protect it (e.g. use https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables or similar).
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务