为家庭局域网中的每个Docker容器设置静态IP

nbnkbykc  于 2023-01-04  发布在  Docker
关注(0)|答案(2)|浏览(145)

我需要我的码头集装箱有一个静态ip地址在我的局域网,所以我可以访问他们的唯一ip。
我试过这样做的网络,但这并不奏效。这是一个例子,码头组成文件,我已经尝试:

version: "3"

services:
   postgres:
    image: postgres:14.1
    container_name: postgres
    restart: always
    ports:
      - "192.168.1.241:5432:5432"
    depends_on:
      - webmin
    environment:
      POSTGRES_USER: openfire
      POSTGRES_PASSWORD: password
      POSTGRES_HOST_AUTH_METHOD: trust
    networks:
      - docker-lab

  webmin:
    image: 'chsliu/docker-webmin'
    container_name: webmin
    restart: always
    ports:
      - "192.168.1.242:10000:10000"
      - "192.168.1.242:53:53/tcp"
      - "192.168.1.242:53:53/udp"
    environment:
      POSTGRES_USER: openfire
      POSTGRES_PASSWORD: password
      POSTGRES_HOST_AUTH_METHOD: trust
    networks:
      - docker-lab

networks:
  docker-lab:
    driver: bridge

当我运行它与docker-compose -f lab.yml up -d-我得到这个错误:

Creating webmin ... 
Creating webmin ... error

ERROR: for webmin  Cannot start service webmin: driver failed programming external connectivity on endpoint webmin (02633ecc5adf4506bb7217472527cea7a4a3a7ef94d5181ebacc1ff6721c5d93): Error starting userland proxy: listen tcp4 192.168.1.242:10000: bind: cannot assign requested address

ERROR: for webmin  Cannot start service webmin: driver failed programming external connectivity on endpoint webmin (02633ecc5adf4506bb7217472527cea7a4a3a7ef94d5181ebacc1ff6721c5d93): Error starting userland proxy: listen tcp4 192.168.1.242:10000: bind: cannot assign requested address

Docker版本:

一米一米一x一米二米一x

系统:

NAME="Fedora Linux"
VERSION="37 (Workstation Edition)"
ID=fedora
VERSION_ID=37
VERSION_CODENAME=""
PLATFORM_ID="platform:f37"
PRETTY_NAME="Fedora Linux 37 (Workstation Edition)"
gblwokeq

gblwokeq1#

您需要使用该指定IP添加两个虚拟IP
/etc/系统管理程序/网络/vip1.netdev

[NetDev]
Name=vip1
Kind=dummy

/etc/系统管理程序/网络/vip2.netdev

[NetDev]
Name=vip2
Kind=dummy

/etc/系统管理/网络/vip1.network

[Match]
Name=vip1

[Network]
Address=192.168.1.241
Mask=255.255.255.0
Broadcast=192.168.1.255

/etc/系统管理/网络/vip2.network

[Match]
Name=vip2

[Network]
Address=192.168.1.242
Mask=255.255.255.0
Broadcast=192.168.1.255

然后重新启动网络服务

sudo systemctl restart systemd-networkd.service

最后再次运行合成

docker compose up -d
woobm2wo

woobm2wo2#

已解决此任务

首先,我创建了虚拟接口:
第一个月
ifconfig eth0:1 192.168.1.242 netmask 255.255.255.0 up
然后,我刚刚运行了我的docker-compose文件,没有网络配置,但与ip的绑定到容器.例如:

postgres:
    image: postgres:14.1
    container_name: postgres
    restart: always
    ports:
      #Binding port to IP (ip:port:port)
      - "192.168.1.241:5432:5432"
    depends_on:
      - webmin
    environment:
      POSTGRES_USER: openfire
      POSTGRES_PASSWORD: password
      POSTGRES_HOST_AUTH_METHOD: trust

This post on edureka帮了我。

相关问题