运行最新Docker ColdFusion镜像时localhost访问8500挂起,127.0.0.1正常
Docker 部署 ColdFusion 时 localhost 访问挂起、127.0.0.1 访问正常问题
基础部署流程
- 拉取 ColdFusion Docker 镜像,执行命令:
docker pull eaps-docker-coldfusion.bintray.io/cf/coldfusion:latest - 编写 docker-compose 配置文件
docker-compose-dev.yml,内容如下:
version: "3.7" services: coldfusion: image: eaps-docker-coldfusion.bintray.io/cf/coldfusion:latest ports: - "8500:8500" networks: coldfusion: hostname: coldfusion volumes: - "~/dev/docker/projects/coldfusion/volumes/app:/app" - "~/dev/docker/projects/coldfusion/volumes/logs:/opt/coldfusion/cfusion/logs" environment: acceptEULA: "YES" password: "ColdFusion123" enableSecureProfile: "false" HOST_USER_ID: ${CURRENT_UID} HOST_GROUP_ID: ${CURRENT_GID} deploy: replicas: 1 restart_policy: condition: any delay: 5s max_attempts: 3 window: 10s healthcheck: test: curl --fail http://localhost:8500 || exit 1 interval: 1m timeout: 3s retries: 3 networks: coldfusion: name: coldfusion common: external: true name: common
- 启动服务,执行命令:
docker stack deploy --compose-file docker-compose-dev.yml coldfusion
服务运行状态
服务启动日志显示 ColdFusion 2018 已完成启动流程,无显性报错,关键日志如下:
Updating webroot to /app Configuring virtual directories Updating password Skipping language updation Serial Key: Not Provided Previous Serial Key: Not Provided Starting ColdFusion Starting ColdFusion 2018 server ... The ColdFusion 2018 server is starting up and will be available shortly. ====================================================================== ColdFusion 2018 server has been started. ColdFusion 2018 will write logs to /opt/coldfusion/cfusion/bin/../logs/coldfusion-out.log ====================================================================== [000] Checking server startup status... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 External Addons: Disabled External Session Storage: Disabled Skipping setup script invocation Secure Profile: Disabled Cleaning up setup directories
异常现象
- 浏览器访问
http://localhost:8500/时请求持续挂起,无响应返回 - 查看挂载目录下的服务日志,执行
tail -f volumes/logs/coldfusion-out.log无新增日志写入,说明请求未抵达 ColdFusion 服务 - 已在 web 根目录
/app下创建测试页面index.cfm,代码内容如下:
hi <cfset firstName = "World"> Hello <cfoutput>#firstName#</cfoutput>! This CFML tutorial was designed for <cfif firstName eq "World"> you! <cfelse> the world to see. </cfif>
- 核心差异验证:将访问地址替换为
http://127.0.0.1:8500/时,可正常返回200响应
已开展的排查操作
- 配置防火墙8500端口放行规则,操作记录如下:
stephane@stephane-pc:~$ sudo ufw allow from 127.0.0.0 to any port 8500; Rules updated stephane@stephane-pc:~$ sudo ufw allow from any to any port 8500; Rules updated Rules updated (v6)
- 检查宿主机
/etc/hosts文件,已存在标准映射:
127.0.0.1 localhost
- 使用
nmap检测本地8500端口状态,结果显示端口处于开放状态:
stephane@stephane-pc:~/dev/docker/projects/coldfusion$ nmap -p 8500 localhost Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-08 12:09 CEST Nmap scan report for localhost (127.0.0.1) Host is up (0.00038s latency). PORT STATE SERVICE 8500/tcp open fmtp Nmap done: 1 IP address (1 host up) scanned in 0.22 seconds
问题根因
Linux 系统对域名的解析遵循 IPv6 优先规则:访问 localhost 时会优先解析到 IPv6 回环地址 ::1,只有 IPv6 连接失败后才会兜底尝试 IPv4 地址 127.0.0.1。
当前 Docker 服务的端口映射默认仅绑定到 IPv4 地址 0.0.0.0:8500,未在 IPv6 的 ::1 地址上监听端口。当浏览器发起 http://localhost:8500 请求时,会优先尝试通过 IPv6 连接 ::1:8500,但该地址上无对应服务监听,就会出现请求持续挂起的现象;而直接访问 127.0.0.1:8500 是纯 IPv4 请求,可直接命中 Docker 映射的端口,因此能正常返回响应。
这一机制也能解释为什么之前的 nmap 检测显示 8500 端口开放,但实际浏览器访问会挂起:nmap 检测时默认优先走 IPv4 通道,没有触发 IPv6 的连接超时流程。问题本质和防火墙规则、/etc/hosts 配置无关。
可落地解决方案
- 方案1:调整 Docker 端口映射规则,同时绑定 IPv4 和 IPv6 地址
修改 docker-compose 配置中的 ports 段,将原有端口映射调整为:
修改完成后重新执行ports: - "0.0.0.0:8500:8500" - ":::8500:8500"docker stack deploy --compose-file docker-compose-dev.yml coldfusion重启服务,即可通过http://localhost:8500正常访问。 - 方案2:修改系统域名解析优先级,强制 IPv4 优先
编辑/etc/gai.conf配置文件,找到优先级配置段,取消注释precedence ::ffff:0:0/96 100这一行,保存配置后系统访问 localhost 就会优先解析为 IPv4 地址127.0.0.1,无需调整 Docker 服务配置。 - 方案3:临时开发规避
日常开发调试时直接使用http://127.0.0.1:8500访问服务,无需额外调整系统或容器配置。
内容的提问来源于stack exchange,提问作者Stephane
相关产品推荐
相关产品推荐

