Description
EXPOSE 22 records a port in the image metadata. Docker can publish declared ports with -P. An SSH service must also be listening before anyone can connect to it.
Potential impact
Automatic publishing can make a running SSH service reachable from unintended networks. Its authentication and patch level then matter.
Remediation
If SSH is unnecessary, remove 22 from EXPOSE and check listeners, explicit port mappings, and firewall rules. Use access-controlled execution and logs for administration. If you need SSH, restrict it to trusted management networks and require strong authentication.
Examples
Both examples start Nginx. Neither starts an SSH daemon.
Before
FROM nginx:1.27-alpine
EXPOSE 80 22
CMD ["nginx", "-g", "daemon off;"]
After
FROM nginx:1.27-alpine
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
The revision declares only port 80. An explicit host mapping for port 22 would still take effect.