Closed Kiendeleo closed 5 years ago
This would probably make camera discovery work too. I've never tried to do what you're doing, but when you get it working... please let us know what you did and we can update documentation! :)
Did this work? If so, would you mind improving the documentation?
I have not had a chance to mess with this other than my initial failed attempts.
Just create the macvlan first. My example local network is 10.0.0.0/24 on local interface eth0:
docker network create -d macvlan \ --subnet=10.0.0.0/24 \ --gateway=10.0.0.1 \ -o parent=eth0 my_net
Then add two networks directives to the docker-compose file, make sure to use a free IP address on your local network.
docker-compose.yml:
version: '3'
services:
unifi-NVR:
container_name: unifi-NVR
image: pducharme/unifi-video-controller:latest
restart: unless-stopped
cap_add:
- SYS_ADMIN
- DAC_READ_SEARCH
logging:
driver: "json-file"
options:
max-size: "1m"
max-file: "5"
networks:
my_net:
ipv4_address: 10.0.0.170
ports:
- "10001:10001"
- "1935:1935"
- "6666:6666"
- "7080:7080"
- "7442:7442"
- "7443:7443"
- "7444:7444"
- "7445:7445"
- "7446:7446"
- "7447:7447"
volumes:
- ./data:/var/lib/unifi-video
environment:
- TZ=Europe/Stockholm
- PUID=99
- PGID=100
- DEBUG=0
networks:
my_net:
external: true
Finally add hostname 'nvr' for 10.0.0.170 to your hostname lookup service and now you can surf to: https://nvr:7443/login
I was able to get this to work by simply removing all of the "-p..." from the run command and adding the --net .... information. It appears that when you try to assign a container to a macvlan network and assign ports it gets confused.
Also attaching it to a macvlan network fixes camera discovery. The cameras are automatically discovered and manage as if the software was installed via a repository.
I would recommend that the documentation is changed to use named volumes for the file locations as well. If you add the plugin: https://github.com/CWSpear/local-persist you can put volumes wherever you want, within reason.
Is there a way to make macvlan
use your local network's dhcp server to setup the network it uses?
From what I understand there are no support in docker to use an external DHCP server. Check this out http://hicu.be/docker-networking-macvlan-bridge-mode-configuration
There is no way of using your routers DHCP server that I am aware of. However, the macvlan setup allows you to restrict addresses to a given scope. This allows you to place the scope in an area of your subnet that the DHCP server doesn't use. For example, this is a common router setup:
Router IP: 192.168.0.1 Subnet: /24 or 255.255.255.0 DHCP Range: 192.168.0.100-192.168.0.254
In this configuration, you can place you macvlan in the 192.168.0.0/24 address space. You just have to set the --ip-range to the space that is not being used by your DHCP server. An example would be:
docker network create -d macvlan \
--subnet=192.168.0.0/24 \
--ip-range=192.168.0.16/28 \
--gateway=192.168.0.1 \
-o parent=eth0 MymacvlanNetwork
This would give you from 192.168.0.16-192.168.0.31 as usable in your macvlan network.
When creating your Docker containers you should still define an IP address and hostname, if they are a server like container, so that the containers are easy to look up. If you don't define an IP address and hostname, the macvlan network will act as a DHCP server for you. If you add the --ip-range correctly you will not get address conflicts.
There is more information about this here:
https://docs.docker.com/v17.09/engine/userguide/networking/get-started-macvlan/
A handy tool for calculating subnets: http://www.subnet-calculator.com
I am planning a full writeup on how to configure this Docker container with a macvlan network when I have time.
I don’t know if this is still usefull, here is a snippet from 1 of my dockers (docker-compose version 3.6) I use macvlan on this host, to expose a service, and use an internal unexposed vlan, for internal container communications: (names have been redacted, offcourse;))
services:
app:
networks:
internal_network: {}
services:
ipv4_address: <ip_address>
networks:
services:
name: lan_services
external: false #set to true, if you want docker-compose, to create the vlan
driver: macvlan
driver_opts:
parent: <interface-name>.<vlan-id>
ipam:
config:
- subnet: subnet/subnetmask
internal_network:
internal: True
PS: I’m embarking on the same road, getting unifi-video-controller working via macvlan, on my network ツ (but I can’t clone the repo, for some reason, my ssh-key is no longer accepted, so I can’t give you my findings yet ;))
I have this docker container working with a macvlan and the local-persist volume plugin.
Let me know if you have any questions.
This isn't about having a hostname, it is about having an actual IP on your local network instead of on the docker network.
Yeah, sorry - I deleted that suggestion after I played with the idea a bit.
If anyone who uses and understands this wanted to create a wiki page for this, that'd be cool. :)
Due to the large number of ports, and for easier management I wanted to have my Unifi Video Server to have its own IP address and domain name. I tried adding
and the server is not visible at the assigned IP address. Also, the
docker container ls
command doesn't show any of the ports that were assigned. I assume I am doing something wrong, as I am fairly new to docker, but I think I am doing things according to the manual