Docker Compose静态IP地址

时间:2020-10-02 01:10:23

标签: linux docker networking docker-compose

我正在尝试使用docker-compose(文件格式版本3.8)部署具有静态IP地址和单个网络的应用程序,我能够创建它们,但IP地址未正确分配给Container。< / p>

docker-compose.yml

version: "3.8"
services:

  nzbhydra2:
    image: linuxserver/nzbhydra2
    container_name: nzbhydra2
    networks:
      mediacenter_network:
        ipv4_address: 172.16.238.10
    restart: always
    environment:
      - PUID=1000
      - PGID=1000
    ports:
      - "5076:5076"
    volumes:
      - /opt/docker/plex/config:/config
      - /opt/docker/jackett/downloads:/downloads

networks:

    mediacenter_network:
      ipam:
        driver: default
        config:
          - subnet: "172.16.238.0/24"
            gateway: 172.16.238.1


由此产生的网络设置如下:

"NetworkSettings": {
            "Bridge": "",
            "SandboxID": "0fab46506aeab52588e2b84e676202150b7016c9be49e7958bf9e367f0bd069d",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "5076/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5076"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/0fab46506aea",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "compose_mediacenter_network": {
                    "IPAMConfig": {
                        "IPv4Address": "172.16.238.10"
                    },
                    "Links": null,
                    "Aliases": [
                        "nzbhydra2",
                        "47aad4695014"
                    ],
                    "NetworkID": "c5953a22f478497c72036bafef32be639200ad69fb37403a6ceb8d23b2ba28d0",
                    "EndpointID": "6138c474befd3449b4c274021bfe212e0dc9ea3e6fd0840171048b5d38b33a11",
                    "Gateway": "172.16.238.1",
                    "IPAddress": "172.16.238.10",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:10:ee:0a",
                    "DriverOpts": null
                }
            }
        }


请注意,未在“” IPAddress“:”“,”

中分配IP地址

我希望它看起来像是我手动完成的,例如:


docker create \
  --name=nzbhydra2_manual_create \
  --restart=always \
  -e PUID=1000 \
  -e PGID=1000 \
  -p 5077:5076 \
  -v /opt/docker/plex/config:/config \
  -v /opt/docker/jackett/downloads:/downloads \
  linuxserver/nzbhydra2

这样做,我可以在“网络设置”中看到分配的IP地址:

        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "2c55f7b547827ef3c9db0299875bfb0c630d407e882ec43011025fcd2b6e6f3b",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "5076/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5077"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/2c55f7b54782",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "23442bcbcf2d2f48b1109d92187e5596989f59fdf26c75784b5027ff52593a72",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "34eef2e62215d1bb10f7513207d4d105ed717dc8d1fed48c180cee7ed75cbaab",
                    "EndpointID": "23442bcbcf2d2f48b1109d92187e5596989f59fdf26c75784b5027ff52593a72",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }


这就是在Portainer中的样子:

手动创建:

使用Compose创建

有人可以让我知道我在Docker Compose文件中做错了什么吗

1 个答案:

答案 0 :(得分:0)

事实证明,我没有做错任何事情,这里的问题是,在Red Hat Enterprise Linux(RHEL)8或CentOS 8上官方不支持Docker CE。我应该提到我在CentOS 8上部署了Containers无论如何,您可以在下面找到解决方案。

https://serverfault.com/questions/987686/no-network-connectivity-to-from-docker-ce-container-on-centos-8