zoukankan      html  css  js  c++  java
  • selenium/standalone-chrome:latest 找不到服务名称解决办法

    selenium/standalone-chrome:latest 找不到服务名称解决办法

    问题概述:

    使用 docker-compose 创建和管理容器,使用镜像selenium/standalone-chrome:latest 创建容器 chrome

    docker-compose文件如下:

    version: '3.6'
    
    services:
      whatweb:
        image: whatweb:v0.0.2
        build:
          context: ./services/whatweb
          dockerfile: Dockerfile-information
        volumes:
          - './services/whatweb:/usr/src/app'
        restart: always
        env_file:
          - whatweb-information.env
        network_mode: host
    
      whatweb-chrome:
        image: selenium/standalone-chrome:latest
        restart: always
        shm_size: 2g
        network_mode: host
    
    

    配置文件如下:

    # chromedriver_url
    COMMAND_EXECUTOR=http://chrome:4444/wd/hub  # 此处的chrome 为容器名称
    

    当启动容器时并没有问题,可能正常使用 4444 端口,但是一旦调用配置文件中的信息就会出现问题

    raised unexpected: MaxRetryError("HTTPConnectionPool(host='whatweb-chrome', port=4444): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f02296f2e90>: Failed to establish a new connection: [Errno -2] Name or service not known'))")",
    

    此时是因为在docker-compose 文件中我们配置的 network 为 host模式,我们是直接使用宿主机的网络配置,并没有出现chrome 与 ip 地址的映射关系,所以服务并不能识别访问http://chrome:4444/wd/hub

    解决办法

    # chromedriver_url
    COMMAND_EXECUTOR=http://127.0.0.1:4444/wd/hub  # 将 Chrome 直接替换为 localhost 地址,会直接调用本机网络配置去访问
    
  • 相关阅读:
    织梦CMS去广告方法 for DedeCMS V5.7
    织梦网站底部的Power by DedeCms怎么去掉?
    java环境变量最佳配置
    HTML课上小结
    PHP四个阶段目标以及第一阶段学习内容
    例子:选项卡和进度条
    例子:轮播效果
    例子:下拉列表
    document对象操作:浏览器页面文件
    Windows对象操作:浏览器窗口信息
  • 原文地址:https://www.cnblogs.com/zhangweijie01/p/12097480.html
Copyright © 2011-2022 走看看