简体   繁体   English

Docker Compose 静态 IP 地址

[英]Docker Compose Static Ip addressing

I am trying to deploy an application with a static ip address and a single network using docker-compose (file format version 3.8), I am able to create them but the ip address is not being correctly assigned to the Container.我正在尝试使用 docker-compose(文件格式版本 3.8)部署具有静态 ip 地址和单个网络的应用程序,我能够创建它们,但未将 ip 地址正确分配给容器。

docker-compose.yml 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


The resulting Network Settings from that are as follows:由此产生的网络设置如下:

"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
                }
            }
        }


Notice the ip address is not being assigned in " "IPAddress": "","请注意,IP 地址未在 " "IPAddress": ""," 中分配

I want it to look like if I was doing it manually, example:我希望它看起来像我手动完成的,例如:


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

Doing it this way, I can see the ip address being assigned in Network Settings:这样做,我可以看到在网络设置中分配的 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
                }
            }
        }


This is how they look like in Portainer:这是它们在 Portainer 中的样子:

Manually Created:手动创建:

Created with Compose:使用 Compose 创建:

Can someone please let me know what I am doing wrong in the Docker Compose file?有人可以让我知道我在 Docker Compose 文件中做错了什么吗?

It turns out I was not doing anything wrong, the issue here was that Docker CE is officially not supported on Red Hat Enterprise Linux (RHEL) 8 or CentOS 8. I should have mentioned I was deploying the Containers on CentOS 8, anyway, below you can find the solution.事实证明我没有做错任何事,这里的问题是 Red Hat Enterprise Linux (RHEL) 8 或 CentOS 8 正式不支持 Docker CE。我应该提到我在 CentOS 8 上部署容器,无论如何,如下你可以找到解决办法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM