Skip to content

Commit c596445

Browse files
poeggiclaude
andauthored
Add new feature and parameter ENABLE_BDS_V6BIND_FIX, to allow IPv4 and IPv6 on the same port (#628)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 09b8859 commit c596445

4 files changed

Lines changed: 62 additions & 8 deletions

File tree

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
3+
*.sh text eol=lf
4+
*.c text eol=lf
5+
*.json text eol=lf
6+
*.md text eol=lf
7+
*.yml text eol=lf
8+
*.yaml text eol=lf
9+
*.ps1 text eol=crlf
10+
11+
build/install-packages text eol=lf
12+
build/setup-arm64 text eol=lf
13+
bin/* text eol=lf

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,23 @@ COPY *.sh /opt/
5353
COPY property-definitions.json /etc/bds-property-definitions.json
5454
COPY bin/* /usr/local/bin/
5555

56+
RUN case "$TARGETARCH" in \
57+
amd64) _arch=x86_64 ;; \
58+
arm64) _arch=aarch64 ;; \
59+
*) echo "[bds-ipv6fix] unsupported arch $TARGETARCH, ENABLE_BDS_V6BIND_FIX will have no effect" >&2; exit 0 ;; \
60+
esac && \
61+
curl -fsSL "https://github.com/poeggi/bds-ipv6fix/releases/latest/download/bds-ipv6fix_linux_${_arch}.so" \
62+
-o /opt/bds-ipv6fix.so
63+
5664
# Available versions listed at
5765
# https://minecraft.wiki/w/Bedrock_Edition_1.11.0
5866
# https://minecraft.wiki/w/Bedrock_Edition_1.12.0
5967
# https://minecraft.wiki/w/Bedrock_Edition_1.13.0
6068
# https://minecraft.wiki/w/Bedrock_Edition_1.14.0
6169
ENV VERSION=LATEST \
6270
SERVER_PORT=19132 \
63-
SERVER_PORT_V6=19133
71+
SERVER_PORT_V6=19133 \
72+
ENABLE_BDS_V6BIND_FIX=false
6473

6574
HEALTHCHECK --start-period=1m CMD /usr/local/bin/mc-monitor status-bedrock --host 127.0.0.1 --port $SERVER_PORT
6675

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ exposing the default IPv4 UDP port:
1313
docker run -d -it -e EULA=TRUE -p 19132:19132/udp -v mc-bedrock-data:/data itzg/minecraft-bedrock-server
1414
```
1515

16-
If your network is dual-stack (IPv4 and IPv6), also map the IPv6 port:
16+
> **NOTE**: if you plan on running a server for a longer amount of time it is highly recommended using a management layer such as [Docker Compose](#deploying-with-docker-compose) or [Kubernetes](#deploying-with-kubernetes) to allow for incremental reconfiguration and image upgrades.
1717
18-
```bash
19-
-p 19132:19132/udp -p 19133:19133/udp
20-
```
18+
If your network is dual-stack (IPv4 and IPv6), also map the IPv6 port: `-p 19132:19132/udp -p 19133:19133/udp`
2119

22-
> **NOTE**: if you plan on running a server for a longer amount of time it is highly recommended using a management layer such as [Docker Compose](#deploying-with-docker-compose) or [Kubernetes](#deploying-with-kubernetes) to allow for incremental reconfiguration and image upgrades.
20+
Alternatively, enable `ENABLE_BDS_V6BIND_FIX=true` to serve both from the same port number - see [IPv6 same-port fix](#ipv6-same-port-fix).
2321

2422
## Upgrading to the latest Bedrock server version
2523

@@ -72,6 +70,7 @@ For Minecraft Java Edition you'll need to use this image instead:
7270
- `DIRECT_DOWNLOAD_URL` (no default): This environment variable can be used to provide a **direct download URL** for the Minecraft Bedrock server `.zip` file. When set, this URL will be used instead of attempting to automatically look up the download link from `minecraft.net`. This is particularly useful for CI/CD environments or when the automatic version lookup is temporarily broken due to website changes. Ensure the URL points directly to the `bedrock-server-VERSION.zip` file.
7371
- `DOWNLOAD_PROGRESS` (default is `false`) : When set to `true`, displays a progress bar during the Bedrock server download instead of running silently.
7472
- `ENABLE_SSH` (default is `false`) : Enable remote console over SSH on port 2222 if this environment variable is set to `true`.
73+
- `ENABLE_BDS_V6BIND_FIX` (default is `false`) : allows `SERVER_PORT` and `SERVER_PORT_V6` to be set to the same port. See [IPv6 same-port fix](#ipv6-same-port-fix). Enabling it should mitigate connectivity issues in dual-stack setups.
7574
- `MC_PACK` (no default): Path inside the container to a single archive file (e.g. `.mcpack`, `.mcworld`, `.mctemplate`, `.mcaddon`, or any zip) or to a directory with the same layout. At startup the archive is unpacked (or the directory is read): top-level `behavior_packs/` is merged into `behavior_packs/`, top-level `resource_packs/` into `resource_packs/`, and all other content (when `level.dat` is present) into `worlds/{LEVEL_NAME}`. For `.mcaddon` archives, which use root-level `data/` (behavior) and `resources/` (resource) folders instead of `behavior_packs/` and `resource_packs/`, these are detected and installed automatically using the pack UUID from each manifest as the folder name.
7675
- `FORCE_WORLD_COPY` (default `false`): When `MC_PACK` contains a world (`level.dat`), set to `true` to remove and replace the existing `worlds/{LEVEL_NAME}` on every startup; otherwise the world is copied only when it does not exist.
7776
- `FORCE_PACK_COPY` (default `false`): When `MC_PACK` contains `behavior_packs/` or `resource_packs/`, set to `true` to remove and replace existing pack folders with the same name on every startup; otherwise each pack is copied only when it does not already exist.
@@ -155,9 +154,33 @@ docker run -d -it --name bds-flat-creative \
155154
## Exposed Ports
156155

157156
- **UDP** 19132 : the Bedrock server port for IPv4 clients, set by `SERVER_PORT`
158-
- **UDP** 19133 : the Bedrock server port for IPv6 clients, set by `SERVER_PORT_V6`
157+
- **UDP** 19133 : the default Bedrock server port for IPv6 clients, set by `SERVER_PORT_V6`
158+
159+
> **NOTE**: with `ENABLE_BDS_V6BIND_FIX=true`, both ports can be set to the same value (e.g. 19132), exposing the same port number for both address families - this is recommended for dual-stack environments to avoid connectivity problems.
160+
161+
## IPv6 same-port fix
162+
163+
BDS binds IPv4 and IPv6 on separate ports by default (19132 and 19133).
164+
Bedrock clients do not implement Happy Eyeballs, so a player whose device
165+
resolves the hostname to IPv6 connects to port 19132 over IPv6 and times out
166+
-- the server only accepts IPv6 on 19133. Set `ENABLE_BDS_V6BIND_FIX=true`
167+
to enable a runtime shim ([bds-ipv6fix](https://github.com/poeggi/bds-ipv6fix))
168+
that patches BDS to allow both address families on the same port number, then
169+
set both properties to the same value:
170+
171+
```yaml
172+
environment:
173+
EULA: "TRUE"
174+
ENABLE_BDS_V6BIND_FIX: "true"
175+
SERVER_PORT: 19132
176+
SERVER_PORT_V6: 19132
177+
ports:
178+
- "19132:19132/udp"
179+
```
159180
160-
**NOTE** that you must append `/udp` when exposing the ports, such as `-p 19132:19132/udp -p 19133:19133/udp`.
181+
> **NOTE**: `SERVER_PORT_V6` equal to `SERVER_PORT` requires `ENABLE_BDS_V6BIND_FIX=true`;
182+
> without it BDS will crash. Always set the IPv6 port via `SERVER_PORT_V6`,
183+
> do not set ports via `server.properties`.
161184

162185
## Volumes
163186

bedrock-entry.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ set-property --file server.properties --bulk /etc/bds-property-definitions.json
446446

447447
export LD_LIBRARY_PATH=.
448448

449+
: "${ENABLE_BDS_V6BIND_FIX:=false}"
450+
if isTrue "${ENABLE_BDS_V6BIND_FIX}"; then
451+
if [[ -f /opt/bds-ipv6fix.so ]]; then
452+
export LD_PRELOAD=/opt/bds-ipv6fix.so
453+
else
454+
echo "WARNING: ENABLE_BDS_V6BIND_FIX=true but bds-ipv6fix.so is not available for this platform"
455+
fi
456+
fi
457+
449458
mcServerRunnerArgs=()
450459
if isTrue "${ENABLE_SSH}"; then
451460
mcServerRunnerArgs+=(--remote-console)

0 commit comments

Comments
 (0)