gpt4 book ai didi

docker-compose 多网络私有(private)和互联网

转载 作者:行者123 更新时间:2023-12-02 19:30:24 29 4
gpt4 key购买 nike

我需要我的容器(本地 grpc_alpine)在连接到内部网络时能够访问互联网。我尝试了以下 yaml 文件:

version: '2'
services:
gr1:
image: grpc_alpine
hostname: gr1
container_name: gr1
privileged: true
stdin_open: true
tty: true
volumes:
- "${PWD}/assets/grpc:/etc/grpc"
networks:
- default
- mynet:
ipv4_address: "10.10.10.11"
environment:
- DEFAULT_GATEWAY=10.10.10.254


networks:

mynet:
ipam:
config:
- subnet: 10.10.10.0/24
gateway: 10.10.10.254

但抛出这个问题:

compose.config.config.find: Using configuration files: ./docker-compose.yml ERROR: compose.cli.main.main: The Compose file './docker-compose.yml' is invalid because: services.gr1.networks contains {"mynet": {"ipv4_address": "10.10.10.11"}}, which is an invalid type, it should be a string

最佳答案

您的 yaml 配置存在一个小问题。 networks services 中的选项需要 map 而不是列表。试试这个:

version: '2'
services:
gr1:
image: grpc_alpine
hostname: gr1
container_name: gr1
privileged: true
stdin_open: true
tty: true
volumes:
- "${PWD}/assets/grpc:/etc/grpc"
networks:
default:
mynet:
ipv4_address: "10.10.10.11"
environment:
- DEFAULT_GATEWAY=10.10.10.254

networks:
mynet:
ipam:
config:
- subnet: 10.10.10.0/24
gateway: 10.10.10.254

关于docker-compose 多网络私有(private)和互联网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51915987/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com