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
121 views
in Technique[技术] by (71.8m points)

Docker Stack one static IP address for whole stack

I have a production environment using Docker on my QNAP, I would like to set up a test environment where I can run experiment out without having to interrupt my production environment. I need to have these containers available to my LAN and would ideally like to have them all use a single IP address rather than NAT or give them each their own individual address (I know how to do that) but I'm not sure how. I've tried playing around with it but I am still new to docker and can't figure it out or know if it even possible. When I have tried the example below only the first container came up for each new IP address

Example... Notes: QNAP IP address is 192.168.2.2 and that everything in this example uses 192.168.2.4 except the last two containers that are 192.168.2.5 (which could be moved to a new stack if needed) Not a working example, for demo

version: '2.4'
services:
  pihole: 
    image: pihole/pihole
    container_name: pihole
    environment:
      - TZ=AMERICA/Denver
    volumes:
      - './etc-pihole/:/etc/pihole/'
      - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
    restart: unless-stopped
    networks:
      qnet-static:
        ipv4_address: 192.168.2.4

  ftpd_server:
    image: stilliard/pure-ftpd
    container_name: pure-ftpd
    ports:
      - "21:21"
    volumes:
      - "/folder_on_disk/data:/home/username/"
    restart: unless-stopped
    networks:
      qnet-static:
        ipv4_address: 192.168.2.4

  mailserver:
    image: docker.io/mailserver/docker-mailserver:latest
    ports:
      - "25:25"
    volumes:
      - maildata:/var/mail
    environment:
      - ENABLE_SPAMASSASSIN=1
    cap_add:
      - NET_ADMIN
      - SYS_PTRACE
    restart: always
    networks:
      qnet-static:
        ipv4_address: 192.168.2.4


  mysql:
    container_name: mysql
    image: mysql:latest
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=root
    ports:
     - "3306:3306"
    networks:
      qnet-static:
        ipv4_address: 192.168.2.5
  
apigw-tomcat:
    container_name: apigw-tomcat
    build: tomcat/.
    ports:
     - "8080:8080"
     - "8009:8009"
    networks:
      qnet-static:
        ipv4_address: 192.168.2.5
    depends_on:
     - mysql

    
networks:
  qnet-static:
    driver: qnet
    ipam:
      driver: qnet
      options:
        iface: "eth0"
      config:
        - subnet: 192.168.2.0/23
          gateway: 192.168.2.1
question from:https://stackoverflow.com/questions/66054231/docker-stack-one-static-ip-address-for-whole-stack

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

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

...