dockercontainersmacvlan

Docker "network connect --ip" static ip not persistent after reboot


I have a Nginx Proxy Manager container, which proxies docker containers as well as some physical devices within host external network.

For NPM to get access to them, I've created a network:

sudo docker network create -d macvlan \
--subnet=192.168.0.0/23 \
--gateway=192.168.0.1  \
-o parent=enp2s0 \
 npm

and added NPM to it with:

sudo docker network connect --ip 192.168.0.12 npm npm_nginxproxymanager_1

The issue with this is that after rebooting the host machine, the IP is not persistent.

NPM is still within that network, but the IP it gets for some reason is automatically assigned, and becomes 192.168.0.1. How can I make the container IP stay 0.12 after reboot?


Solution

  • As I discussed before, you are already using the --ip network setting to set the IP.

    To keep it persistent across session, you would need to add that docker network connect directive in a .bashrc or .profile setting file, to be executed when you log in.
    Or set it up as a service, like chung1905/docker-network-connector does.