Settting a docker container to a static IP via Docker compose

Trying to create a static ip on my unifi container. I can’t seem to get the network to find it. Here’s m network settings in docker compose:

services:
unifi-os-server:
image: Package unifi-os-server · GitHub
networks:
unifi_network:
ipv4_address: 192.168.0.50
container_name: Unifi-OS-Server
cgroup: host
cap_add:
- NET_RAW
- NET_ADMIN
extra_hosts:
host.docker.internal: host-gateway
.
networks:
unifi_network:
name: Unifi OS Server
driver: bridge
ipam:
config:
- subnet: 192.168.0.0/24
gateway: 192.168.0.1

Virtual Switch created:

Virtual Switch:
Container Network (br-656dddb1c5d3)
IP Address:
192.168.0.1
Physical:

Virtual:
Unifi-OS-Server_Virtual Adapter 1
Member:
Container Station

I stumped getting this working. I don’t know if the problem lies in the docker compose settings or the virtual switch is getting setup wrong. Anyone here can help?

You need to paste the compose in preformated text quotes, otherwise it will not post correctly

Did you see the qnet manual?

Thanks for that link. I lost the qnet drivers for dhcp and static.

After banging my head for hours, I did get it to work changing the network settings:

driver: macvlan
driver_opts:
parent: eth2

Curiously, should I use the qnet static driver instead?

Hi, @Hypnosis4u2nv The following information comes from our RD team.

Whether to use qnet over macvlan depends on your requirements.

macvlan is sufficient if your only goal is to make the container accessible via a static LAN IP from other devices on the network.

However, if you also need the QNAP host system or other containers on the same NAS to communicate with the deployed container, qnet is the correct choice — macvlan has a known limitation where the host cannot reach containers on the macvlan interface.

For a step-by-step guide on deploying the UniFi container through the Container Station UI, refer to the following FAQ: How to Deploy UniFi Network Application via Docker on QNAP NAS? | QNAP

Thanks for the explanation of the differences between the two drivers. Seeing as I only need Unifi OS Server to communicate with the other Unifi devices on my network (inform/adoption) and nothing else within the QNAP host/containers, I’ll stick with the macvlan setting.

So it’s not difficult if you use the correct YAML. Here’s the full YAML file for my Uptime Kuma container. Pay attention to the “Networks” section…

services:
  uptime-kuma:
    image: louislam/uptime-kuma:2
    container_name: uptime-kuma
    restart: always
    ports:
      - "3001:3001"  # This maps the container port "3001" to the host port "3001"
    volumes:
      - /share/Container/uptime-kuma:/app/data  # Configuring persistent storage
    environment:
      - TZ=America/Chicago  # Set the timezone (change to your preferred local timezone so monitoring times are the same)
      - UMASK=0022  # Set your file permissions manually
    networks:
      kuma-network:
        ipv4_address: 192.168.1.23
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3001"]
      interval: 30s
      retries: 3
      start_period: 10s
      timeout: 5s
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

networks:
  kuma-network:
    driver_opts:
      iface: eth0
    driver: qnet
    ipam:
      driver: qnet
      options:
        iface: eth0
      config:
        - subnet: 192.168.0.0/23
          gateway: 192.168.1.1

A bit of confusion here.

Your using a static IP of 192.168.1.23 but your defined network subnet is 192.168.0.0/23?

My subnet config also defines the CIDR as /24 versus /23 that you set. I don’t know what affect that has with my setup using the macvlan driver, but I see in the QNAP documents for qnet driver using that /23 annotation.

!92.168.0.0/23 has a subnet mask of 255.255.254.0. It allows use of IPs from 192.168.0.1 to 192.168.1.254.

Nothing “special” about it. Just like a 10.0.0.0/8 (255.0.0.0) allows you to use IPs from 10.0.0.1 to 10.255.255.254.

I simply needed/wanted a larger sized network.

Just set things for your network size.

Thanks for that explanation!