无效的顶级属性"external_links" [英] Invalid top-level property "external_links"

查看:80
本文介绍了无效的顶级属性"external_links"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下docker-compose文件内容:

I have the following docker-compose file content:

version: '3.4'
services:
  local-app:
    build: ./app/
    command: node app
    ports:
      - '7001:7001'
    links:
      - search-svc 
networks:
  docker_app-network:
    external: true
external_links:
  -search-svc

基本上,我想做的是将"local-app"容器与另一个已经运行的容器"search-svc"链接.通过运行docker compose,我得到以下错误:

Basically what I 'm trying to do is to link the ' local-app ' container with another already running container the ' search-svc '. By running the docker compose I get the following error:

撰写文件'./docker-compose.yaml'无效,因为:无效的顶级属性"external_links".此Compose文件的有效顶级部分为:机密,版本,卷,服务,配置,网络和以"x-"开头的扩展名.您可能会看到此错误,因为使用的是错误的Compose文件版本.指定受支持的版本(例如"2.2"或"3.3")并将您的服务定义放在 services 键下,或者省略 version 键并将您的服务定义放在要使用版本1的文件的根.

The Compose file './docker-compose.yaml' is invalid because: Invalid top-level property "external_links". Valid top-level sections for this Compose file are: secrets, version, volumes, services, configs, networks, and extensions starting with "x-". You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1.

我已经阅读了文档,但是找不到解决我问题的方法.有人可以提出任何可能有用的建议吗?

I have read the documentation but I can't find any solution to my problem. Can anyone suggest anything that might help?

预先感谢

推荐答案

Yaml文件对空间敏感.您试图在文件的顶层而不是服务的一部分定义 external_links .在语法上应该是正确的:

Yaml files are space sensitive. You tried to define external_links at the top level of the file rather than as part of a service. This should by syntactically correct:

version: '3.4'
services:
  local-app:
    build: ./app/
    command: node app
    ports:
      - '7001:7001'
    links:
      - search-svc 
    external_links:
      - search-svc
networks:
  docker_app-network:
    external: true

也就是说,链接在docker中已被弃用,首选使用通用网络(不包括名为 bridge 的默认桥接网络),然后使用集成的DNS服务器进行服务发现.看起来您已经定义了公用网络,但没有使用它.这会将您的服务放在该网络上,并依赖DNS:

That said, linking is deprecated in docker, it is preferred to use a common network (excluding the default bridge network named bridge) and then use the integrated DNS server for service discovery. It looks like you have defined your common network but didn't use it. This would place your service on that network and rely on DNS:

version: '3.4'
services:
  local-app:
    build: ./app/
    command: node app
    ports:
      - '7001:7001'
    networks:
      - docker_app-network
networks:
  docker_app-network:
    external: true

这篇关于无效的顶级属性"external_links"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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