Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
docker可组成多个专用网络和internet_Docker_Docker Compose - Fatal编程技术网

docker可组成多个专用网络和internet

docker可组成多个专用网络和internet,docker,docker-compose,Docker,Docker Compose,我需要我的容器(本地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_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:使用配置文件: ./docker-compose.yml错误:compose.cli.main.main:组合文件 “./docker compose.yml”无效,因为:services.gr1.networks 包含{“mynet”:{“ipv4_地址”:“10.10.10.11”},这是一个 无效类型,它应该是字符串


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