如何在Docker Compose V3中扩展服务? [英] How to extend service in Docker Compose V3?

查看:203
本文介绍了如何在Docker Compose V3中扩展服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 docker-compose.yml ,它看起来像是

I have a docker-compose.yml which looks like

version: '2'
services:
  redis:
    image: redis

  mysqldb:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=passme
      - MYSQL_DATABASE=mydb
      - MYSQL_USER=root

  base:
    build: .
    volumes:
      - .:/proj
    environment:
      - ENV_1=Value_1
      - ENV_2=Value_2
      - ENV_3=Value_3

  worker:
    extends:
      service: base
    command: celery -A proj worker --loglevel=debug
    links:
      - redis
      - mysqldb
    depends_on:
      - mysqldb

  web:
    extends:
      service: base
    links:
      - mysqldb
      - redis
    depends_on:
      - mysqldb
    ports:
      - "8000:8000"
    command: python manage.py runserver 0.0.0.0:8000



现在,我要 升级 版本3


从文档中


<$较早的Compose文件格式支持c $ c> extends 关键字,直到Compose文件版本2.1 (请参见v1中的扩展和v2中的扩展),但是 在Compose 版本3.x

The extends keyword is supported in earlier Compose file formats up to Compose file version 2.1 (see extends in v1 and extends in v2), but is not supported in Compose version 3.x

$中不受支持b
$ b




所以,这是我的问题,如何使用Version-3 docker-compose文件而不丢失当前的功能



So, here is my question, How can I use Version-3 docker-compose file without losing my current functionalities?

推荐答案

扩展服务扩展之后的版本3

Extending services isn't supported in version 3 after removal of extends.

至于解决方法,您可以使用 docker-compose addons ,例如

As for workaround, you can use docker-compose addons, e.g.

include:
    - http://example.com/compositions/servicea.yaml
    - http://example.com/compositions/serviceb.yaml

namespace: core

web:
    image: example/service_a:latest
    links: ['servicea.web', 'serviceb.api']






另一种方法是从命令行包括多个作曲家文件(带有多个 -f 选项)。请参阅:在部署时添加对多个撰写文件的支持。例如,


Another way is to include multiple composer files from the command-line (with multiple -f options). See: Add support for multiple composefile when deploying. E.g.

docker-compose -f submodules/A_SUB_PROJECT/docker-compose.yml -f submodules/B_SUB_PROJECT/docker-compose.yml config | docker-compose -f - up

来源:在使用来自不同目录的多个docker-compose.yml文件时,未正确遵循本地路径

通常,版本3更适合于Swarm / Kube堆栈,因此请考虑使用它。

In general, version 3 is more ideal for Swarm/Kube stacks, so consider using it.

例如

docker stack deploy -c docker-compose.yml mystack1
docker stack deploy -c another/docker-compose.yml mystack2




如果您不使用Swarm或Docker Enterprise Kubernetes堆栈,则没有理由使用v3。坚持使用v2.4,您将获得所有 docker-compose cli功能,包括扩展 depends_on ,扩展字段,甚至还有带有健康检查的 depends_on (以避免 wait-for-it 脚本。)

If you're not using Swarm or Docker Enterprise Kubernetes stacks, there is no reason to use v3. Stick with v2.4, and you get all the docker-compose cli features including extends, depends_on, extension fields, and even depends_on with healthchecks (to avoid wait-for-it scripts).






相关:


Related:

  • Include external config
  • feature: including external docker-compose.yml
  • Add support for extends feature in Compose v3 / docker stack deploy
  • extends not supported in version 3 schema

这篇关于如何在Docker Compose V3中扩展服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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