码头工人撰写覆盖端口属性,而不是合并它 [英] docker compose override a ports property instead of merging it

查看:59
本文介绍了码头工人撰写覆盖端口属性,而不是合并它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的docker compose配置看起来像这样:

My docker compose configs look like this:

docker-compose.yml

docker-compose.yml

version: '3.5'

services:
    nginx:
        ports:
            - 8080:8080

docker-compose.prod.yml

docker-compose.prod.yml

version: '3.5'

services:
    nginx:
        ports:
            - 80:80

现在,当我运行命令时: docker-compose -f docker-compose.yml -f docker-compose.prod.yml up nginx在主机上公开了两个端口: 8000 80 ,因为它合并了端口属性:

Now, when I run command: docker-compose -f docker-compose.yml -f docker-compose.prod.yml up the nginx exposes on host machine two ports: 8000 and 80, because it merges ports properties:

version: '3.5'

services:
    nginx:
        ports:
            - 8080:8080
            - 80:80

是否有一种方法可以覆盖它?我只想显示端口 80

Is there a way to override it? I want to expose only port 80

推荐答案

此行为记录在 https://docs.docker.com/compose/extends/#adding-and-overriding-configuration

对于多值选项 ports expose external_links dns dns_search tmpfs ,Compose将两组值连接起来

For the multi-value options ports, expose, external_links, dns, dns_search, and tmpfs, Compose concatenates both sets of values

由于 ports 将是您所有撰写文件中端口的串联,所以我建议创建一个新的 docker-compose.dev.yml 文件,其中包含您的开发端口映射,将其从基本 docker-compose.yml 文件中删除.

Since the ports will be the concatenation of the ports in all your compose files, I would suggest creating a new docker-compose.dev.yml file which contains your development port mappings, removing them from the base docker-compose.yml file.

正如Nikson所说,您可以命名此 docker-compose.override.yml 来自动应用您的开发配置,而无需链接docker-compose文件.如果您手动指定另一个替代文件(例如 docker-compose -f docker-compose.yml -f docker-compose.prod.yml )

As Nikson says, you can name this docker-compose.override.yml to apply your development configuration automatically without chaining the docker-compose files. docker-compose.override.yml will not be applied if you manually specify another override file (e.g. docker-compose -f docker-compose.yml -f docker-compose.prod.yml)

这篇关于码头工人撰写覆盖端口属性,而不是合并它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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