容器不与docker-compose版本2相关联 [英] Containers are not linked with docker-compose version 2

查看:131
本文介绍了容器不与docker-compose版本2相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从版本1升级到版本2的docker-compose文件。



它设置了一个带有Firefox浏览器的简单Selenium中心。 >

当我将其设置为版本1时,启动正常。当我使用版本2进行设置时,ff容器返回未与正在运行的Hub容器相关联并退出。



当我研究并理解它的时候,容器之间的联系有什么困难。



有没有解决方案?我错过了什么?

 版本:'2'
服务:
hub:
container_name:hub
image:selenium / hub
ports:
- 8080:4444#HOST:CONTAINER
曝光:
- 4444

ff:
container_name:ff
image:selenium / node-firefox
链接:
- hub
曝光:
- 5555


解决方案

将环境变量添加到<$ c $ Docker Compose文件的c> ff 部分(您可以删除链接):

  ff :
container_name:ff
image:selenium / node-firefox
环境:
- HUB_PORT_4444_TCP_ADDR = hub
曝光:
- 5555

Compose版本2使用不同风格的网络。从升级指南


链接创建的环境变量已被弃用于某些
的时间。在新的Docker网络系统中,它们已被删除。您
应该直接连接到适当的主机名,或者使用链接主机名自己设置
相关环境变量。


网络文档


链接不需要启用服务进行通信 - 通过
默认,任何服务都可以到达该服务的
名称的任何其他服务


Selenium docker文件使用ENV变量的版本1风格的网络。在代码中,如果该变量未设置(其中Docker曾经做过)entry_point.sh命令退出。提供变量明确地解决了这一点。


I have a docker-compose file that I upgraded from version 1 to version 2.

It set ups a simple Selenium hub with a firefox node.

When I set it up as version 1 it launches fine. When I set it up with version 2 the ff container returns "Not linked with a running Hub container" and exits.

As I researched it and understood it , is that the linkage between the containers somehow suffers.

Is there a solution ?? Am I missing something ??

version: '2'
services:
  hub:
    container_name: hub
    image: selenium/hub 
    ports:
      - "8080:4444" # HOST:CONTAINER
    expose:
      - "4444" 

  ff:
    container_name: ff
    image: selenium/node-firefox 
    links:
      - hub
    expose:
      - "5555" 

解决方案

Add an environment variable to your ff section of the Docker Compose file (and you can remove the link):

ff:
  container_name: ff
  image: selenium/node-firefox
  environment:
    - HUB_PORT_4444_TCP_ADDR=hub
  expose:
    - "5555"

Compose version 2 uses a different style of networking. From the upgrading guide:

environment variables created by links have been deprecated for some time. In the new Docker network system, they have been removed. You should either connect directly to the appropriate hostname or set the relevant environment variable yourself, using the link hostname.

From the networking documentation:

links are not required to enable services to communicate - by default, any service can reach any other service at that service’s name.

The Selenium dockerfile uses version 1 style networking by ENV variable. Here in the code, if that variable isn't set (which Docker used to do) the entry_point.sh command exits. Providing the variable explicitly solves this.

这篇关于容器不与docker-compose版本2相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆