[英]How to parameterize dockerfile with .env?
This does not solve my problem, as I have no escaping issues. 这并不能解决我的问题,因为我没有 escaping 问题。
I have a rabbit.env
:我有一个rabbit.env
:
NETWORK_NAME=uv_atp_network
and a dockerfile和一个 dockerfile
version: '2.3'
networks:
atp:
name: $NETWORK_NAME
external: true
services:
rabbitmq_local:
image: 'rabbitmq:3.6-management-alpine'
ports:
- '5672:5672'
- '15672:15672'
networks:
- $NETWORK_NAME
Both in the same folder.两者都在同一个文件夹中。
When running跑步时
@pytest.mark.usefixtures("network",)
def test_rabbit_up(client, session_scoped_container_getter):
pass
which calls docker-compose up
behind the scenes , I am getting 在幕后调用docker-compose up
,我得到
Service "rabbitmq_local" uses an undefined network ""
What am I doing wrong?我究竟做错了什么?
In the Compose file, you've named the network atp
在 Compose 文件中,您已将网络命名为atp
networks:
atp: # <-- you need this name
settings: don't matter to this naming question
and so you need to use that name when you refer to it in a container definition因此,当您在容器定义中引用它时,您需要使用该名称
services:
rabbitmq_local:
networks:
- atp # <-- the Compose file name of the network
Since this name is local to the Compose file, you can choose any name you want.由于此名称是 Compose 文件的本地名称,因此您可以选择所需的任何名称。 In particular, you're allowed to name the network default
, which reconfigures the default network Compose creates ;特别是,您可以将网络命名为default
,这会重新配置 Compose 创建的默认网络; if you do this, you don't need to mention it for individual services.如果您这样做,则无需针对个别服务提及它。
networks:
default: { external: true, name: $NETWORK_NAME }
services:
rabbitmq_local:
# no networks:, Compose will provide `networks: [default]` for you
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.