You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将正常运行的Ansible部署Memcached转为Docker-Compose部署失败求助

Memcached容器化迁移(Docker-Compose)连接失败问题排查

之前用Ansible部署的Memcached服务运行正常,转用Docker-Compose部署后出现连接失败错误,错误日志如下:

error.EMERGENCY: An exception was raised while creating "AbcRedirect\Redirector"; no instance returned {"exception":"[object] (Zend\ServiceManager\Exception\ServiceNotCreatedException(code: 0): An exception was raised while creating "AbcRedirect\Redirector"; no instance returned at /srv/www/xxxxxxx/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:941, Zend\ServiceManager\Exception\ServiceNotCreatedException(code: 0): An exception was raised while creating "xxxxx\Redirect\Strategy\ThemeStrategy"; no instance returned at /srv/www/xxxxxxxxxxxx/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:941, Zend\ServiceManager\Exception\ServiceNotCreatedException(code: 0): An exception was raised while creating "xxxxxxx\Service\ThemeErpUrlService"; no instance returned at /srv/www/xxxxxxxxxxxx/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:941, Zend\Cache\Exception\RuntimeException(code: 0): SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY at /srv/www/xxxxxxxxx/vendor/zendframework/zend-cache/src/Storage/Adapter/Memcached.php:651)","file":"/srv/www/xxxxxxxxxxxx/vendor/xxx/xxxx-bootstrap/src/Module.php","line":71,"class":"xxxx\Bootstrap\Module","function":"xxx\Bootstrap{closure}","cli":false,"host":"en-xxxx.xxx.xxx.xx","uri":"/","user_ip":"172.100.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36","request_method":"GET"}

原正常运行的Ansible部署任务

---
# Install Memcached
- name: ensure Memcached is installed
  yum:
    name:
      - memcached
    state: present
  become: yes

# Configure Memcached
- name: configure Memcached
  template:
    src: memcached.conf.j2
    dest: "{{ memcached_config_file }}"
  notify: restart memcached
  become: yes

# Enable on boot
- name: ensure Memcached is started and enabled on boot
  service:
    name: memcached
    state: started
  become: yes

当前使用的Docker-Compose配置(存在问题)

version: '3.7'
services:
  xxxx-dev:
    image: centos7
    container_name: dev-app
    hostname: dev
    volumes:
      - dev-app-nfsmount:${CONTAINER_MOUNT_DIR}
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    privileged: true
    networks:
      dev-online:
        ipv4_address: 172.100.0.2
    ports:
      - 443:443
      - 6082:6082
      - 9001:9001
      - 5672:5672
      - 15672:15672
      - 29015:29015
    extra_hosts:
      - dev-app:127.0.0.1
      - dev-memcached:172.100.0.9

问题排查与解决步骤

  • 补全Memcached服务定义:当前docker-compose.yml中未包含Memcached服务,仅通过extra_hosts指定了IP。若要在Docker环境部署Memcached,需添加对应的服务配置到docker-compose.yml中:
    memcached:
      image: memcached:latest
      container_name: dev-memcached
      networks:
        dev-online:
          ipv4_address: 172.100.0.9
      command: memcached -m 64 -p 11211 -u memcached
    
  • 验证网络连通性:进入应用容器内部,执行telnet 172.100.0.9 11211或nc -zv 172.100.0.9 11211,确认能否连接到Memcached端口。同时检查Memcached配置是否允许外部连接(比如原Ansible的memcached.conf是否绑定0.0.0.0而非仅127.0.0.1)。
  • 核对应用配置:确认应用中Memcached的地址、端口配置与Docker环境中的服务一致,比如是否指向dev-memcached或172.100.0.9,端口是否为默认的11211。
  • 确认网络归属:确保应用容器与Memcached服务处于同一Docker网络dev-online下,否则extra_hosts指定的IP无法正常访问。若Memcached运行在宿主机,需开放宿主机11211端口,并让应用容器通过宿主机实际IP或host.docker.internal(部分环境)连接。

内容的提问来源于stack exchange,提问作者Rajsekar Reddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 02:01:10