I should be slightly more concise; it’s been awhile since messing with this again, and just re-checked everything, and refreshed my memory.
Using the short syntax as shown above, used to expose both IP6 and IP4 ports, but now it only exposes IP6 ports.
For example, I just fired up a test container using this for the ports:
ports:
- '9999:9999'
and then to check it, use:
netstat -lnt | awk '{print $4}'
It shows this (note no IP4 port 9999, but there is an IP6 9999):
Also, looking in Portainer, only shows this (no port 9999 shown at all, either 4 or 6):

Now, when I use long syntax:
- published: 9999
target: 9999
protocol: 'tcp'
mode: 'host'

System:
Client: Docker Engine - Community
Version: 24.0.7
API version: 1.43
Go version: go1.20.10
Git commit: afdd53b
Built: Thu Oct 26 09:08:01 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.20.10
Git commit: 311b9ff
Built: Thu Oct 26 09:08:01 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.26
GitCommit: 3dd1e886e55dd695541fdcd67420c2888645a495
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
In WSL/Ubuntu/Windows 10
Addition:
I thought maybe something changed with Docker and now you must specify for example /tcp
to the short syntax:
ports:
- '9999:9999/tcp'
But after testing, it made no difference.