Hi All,<\/p>\n
I’ve recently started studying docker and docker compose and as my first task was able to build a container fairly quickly. But I just wanted to see if it’s possible to have a container’s IP different to that of your host.<\/p>\n
For example: My host Ip is 192.168.0.110, I want my pihole to be of a different IP 192.168.0.150 for example<\/p>\n
I tried creating a macvlan and setting the ServerIP variable to no success and was wondering if anyone had already done this and to see if it’s possible<\/p>\n
I’m running docker and docker compose on a raspbian VM<\/p>\n
My code is as follows:<\/p>\n
version: \"3\"\n# https://github.com/pi-hole/docker-pi-hole/blob/master/README.md\nservices:\n pihole:\n container_name: pihole\n image: pihole/pihole:latest\n hostname: pi-hole\n #ip: \"192.168.0.201\"\n # For DHCP it is recommended to remove these ports and instead add: network_mode: \"host\"\n ports:\n - \"53:53/tcp\"\n - \"53:53/udp\"\n - \"67:67/udp\"\n - \"80:80/tcp\"\n - \"443:443/tcp\"\n environment:\n ServerIP: \"192.168.0.130\"\n TZ: 'America/Chicago'\n WEBPASSWORD: 'Password123'\n # Volumes store your data between container upgrades\n volumes:\n - './etc-pihole/:/etc/pihole/'\n - './etc-dnsmasq.d/:/etc/dnsmasq.d/'\n # run `touch ./var-log/pihole.log` first unless you like errors\n # - './var-log/pihole.log:/var/log/pihole.log'\n dns:\n - 127.0.0.1\n - 1.1.1.1\n #- 192.168.1.107\t\n # Recommended but not required (DHCP needs NET_ADMIN)\n # https://github.com/pi-hole/docker-pi-hole#note-on-capabilities\n cap_add:\n - NET_ADMIN\n restart: unless-stopped\n # networks:\n # - dockervlan\n# networks:\n # dockervlan:\n # #This interface should be defined as using null driver. Do not remove it.\n # driver: null\n # driver_opts:\n # parent: eth0\n # ipam:\n # config:\n # - subnet: \"192.168.0.0/24\"\n# # ip_range: \"192.168.0.128/27\"\n# # gateway: \"192.168.0.1\"\n # dockervlan:\n # #This is the interface which is used for containers networking\n # driver: macvlan\n # driver_opts:\n # parent: eth0\n # ipam:\n # config:\n # - subnet: \"192.168.0.0/24\"\n# ip_range: \"192.168.0.128/27\"\n# gateway: \"192.168.0.1\"\n<\/code><\/pre>\nI even tried to create a new network interface<\/p>\n
sudo ip link add dockervlan link eth0 type macvlan mode bridge\nsudo ip addr add 192.168.0.249/32 dev dockervlan\nsudo ip link set dockervlan up\nsudo ip route add 192.168.0.128/27 dev dockervlan\n<\/code><\/pre>\nBut could not get the Ip to change, so I commented the network isolation stuff and run with the IP same as the host<\/p>\n
Any help would be greatly appreciated<\/p>\n
Thanks,<\/p>\n
Ace.<\/p>","upvoteCount":8,"answerCount":1,"datePublished":"2021-06-05T08:41:48.000Z","author":{"@type":"Person","name":"aceelsheik","url":"https://community.spiceworks.com/u/aceelsheik"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi All,<\/p>\n
I’ve recently started studying docker and docker compose and as my first task was able to build a container fairly quickly. But I just wanted to see if it’s possible to have a container’s IP different to that of your host.<\/p>\n
For example: My host Ip is 192.168.0.110, I want my pihole to be of a different IP 192.168.0.150 for example<\/p>\n
I tried creating a macvlan and setting the ServerIP variable to no success and was wondering if anyone had already done this and to see if it’s possible<\/p>\n
I’m running docker and docker compose on a raspbian VM<\/p>\n
My code is as follows:<\/p>\n
version: \"3\"\n# https://github.com/pi-hole/docker-pi-hole/blob/master/README.md\nservices:\n pihole:\n container_name: pihole\n image: pihole/pihole:latest\n hostname: pi-hole\n #ip: \"192.168.0.201\"\n # For DHCP it is recommended to remove these ports and instead add: network_mode: \"host\"\n ports:\n - \"53:53/tcp\"\n - \"53:53/udp\"\n - \"67:67/udp\"\n - \"80:80/tcp\"\n - \"443:443/tcp\"\n environment:\n ServerIP: \"192.168.0.130\"\n TZ: 'America/Chicago'\n WEBPASSWORD: 'Password123'\n # Volumes store your data between container upgrades\n volumes:\n - './etc-pihole/:/etc/pihole/'\n - './etc-dnsmasq.d/:/etc/dnsmasq.d/'\n # run `touch ./var-log/pihole.log` first unless you like errors\n # - './var-log/pihole.log:/var/log/pihole.log'\n dns:\n - 127.0.0.1\n - 1.1.1.1\n #- 192.168.1.107\t\n # Recommended but not required (DHCP needs NET_ADMIN)\n # https://github.com/pi-hole/docker-pi-hole#note-on-capabilities\n cap_add:\n - NET_ADMIN\n restart: unless-stopped\n # networks:\n # - dockervlan\n# networks:\n # dockervlan:\n # #This interface should be defined as using null driver. Do not remove it.\n # driver: null\n # driver_opts:\n # parent: eth0\n # ipam:\n # config:\n # - subnet: \"192.168.0.0/24\"\n# # ip_range: \"192.168.0.128/27\"\n# # gateway: \"192.168.0.1\"\n # dockervlan:\n # #This is the interface which is used for containers networking\n # driver: macvlan\n # driver_opts:\n # parent: eth0\n # ipam:\n # config:\n # - subnet: \"192.168.0.0/24\"\n# ip_range: \"192.168.0.128/27\"\n# gateway: \"192.168.0.1\"\n<\/code><\/pre>\nI even tried to create a new network interface<\/p>\n
sudo ip link add dockervlan link eth0 type macvlan mode bridge\nsudo ip addr add 192.168.0.249/32 dev dockervlan\nsudo ip link set dockervlan up\nsudo ip route add 192.168.0.128/27 dev dockervlan\n<\/code><\/pre>\nBut could not get the Ip to change, so I commented the network isolation stuff and run with the IP same as the host<\/p>\n
Any help would be greatly appreciated<\/p>\n
Thanks,<\/p>\n
Ace.<\/p>","upvoteCount":8,"datePublished":"2021-06-05T08:41:48.000Z","url":"https://community.spiceworks.com/t/docker-compose-pihole-on-a-different-ip-than-host/801894/1","author":{"@type":"Person","name":"aceelsheik","url":"https://community.spiceworks.com/u/aceelsheik"}}]}}