Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

Network IP address for docker compose

tl;dr I want every container in this stack to use the same IP & MAC address and be on my local network but need help on how to

For starters I'm new to docker and docker-compose. I made a docker-stack for my Plex Servers (three of them, one for movies by general categories/tv-shows, music, and holidays) with each one having its own IP address & MAC on my local network and now I want to make a second stack for some of my media management tools but this time I'd like the whole stack to use one IP address and MAC address but I haven't been able to figure out how to do it correctly/so it works This is running on a QNAP NAS (TVS1282v3/QTS) but I am working through the CLI as I leaned that if I do a docker-compose through container station that it won't create the network for me

version: '2.4'

services:
  Sonarr:
    image: linuxserver/sonarr
    container_name: Sonarr
    environment:
      - TZ=AMERICA/Denver
      - name= Sonarr
    volumes:
      - /share/MediaManagement/Sonarr/config:/config:rw
      - /share/MediaManagement/rip:/rip:rw
      - /share/Plex:/Plex:rw
    ports:
      - 8989:8989
    restart: unless-stopped

  Radarr:
    image: linuxserver/radarr
    container_name: Radarr
    environment:
      - TZ=AMERICA/Denver
      - name= Radarr
    volumes:
      - /share/MediaManagement/Radarr/config:/config:rw
      - /share/MediaManagement/rip:/rip:rw
      - /share/Plex:/Plex:rw
    ports:
      - 7878:7878
    restart: unless-stopped

  Lidarr:
    image: linuxserver/lidarr
    container_name: Lidarr
    hostname: Lidarr
    environment:
      - TZ=AMERICA/Denver
      - name= Lidarr
    volumes:
      - /share/MediaManagement/Lidarr/config:/config:rw
      - /share/MediaManagement/rip:/rip:rw
      - /share/Plex:/Plex:rw
    ports:
      - 8686:8686
    restart: unless-stopped

  networks:
    qnet-static:
      ipv4_address: 192.168.2.100
    mac_address: 05:4A:AA:08:51:43
    
networks:
  qnet-static:
    driver: qnet
    ipam:
      driver: qnet
      options:
        iface: "eth0"
      config:
        - subnet: 192.168.2.0/23
          gateway: 192.168.2.1

I have also tried it like how it was set up in my Plex compose file where I put

services:
  NameOfService:
    mac_address: 05:4A:AA:08:51:43
    networks:
      qnet-static:
        ipv4_address: 192.168.2.100
....
networks: ##At the end, not in each service##
  qnet-static:
    driver: qnet
    ipam:
      driver: qnet
      options:
        iface: "eth0"
      config:
        - subnet: 192.168.2.0/23
          gateway: 192.168.2.1

in each service but only the first container worked....

I also tried this at one point but still no luck/ it's syntax is wrong

networks:
  qnet-static:
    driver: qnet
    ipam:
      driver: qnet
      options:
        iface: "eth0"
      config:
        - subnet: 192.168.2.0/23
          gateway: 192.168.2.250
    ipv4_address: 192.168.2.100
  mac_address: 05:4A:AA:08:51:43

Any help would be appreciate it as I am probably just missing a minor piece


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Delete absolutely all of the networks: settings in the file. Don't try to manually assign IP address to containers or configure their MAC addresses.

Your containers will be accessible on your host's IP address, using the first ports: number for each. As far as other hosts on your network are concerned, the processes in containers will be indistinguishable from other services not running in containers.

You also do not need to manually set container_name: or hostname: in most circumstances. There are additional details of the Compose networking environment in Networking in Compose in the Docker documentation, though this mostly focuses on connections between containers. You usually don't need to think about the container-private IP address or (especially) the artificial MAC address within the container network environment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...