Skip to content

Instantly share code, notes, and snippets.

@natcl
Created September 26, 2018 14:31
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save natcl/3d881d00a56c8a961e6dab8ba51a5a37 to your computer and use it in GitHub Desktop.
Save natcl/3d881d00a56c8a961e6dab8ba51a5a37 to your computer and use it in GitHub Desktop.
docker-compose static IP example
version: '3'
networks:
mynetwork:
ipam:
config:
- subnet: 172.20.0.0/24
services:
nodered1:
image: nodered/node-red-docker
ports:
- "1880:1880"
restart: always
environment:
- TZ
- IP_BROKER=mqtt
- DOCKER=true
- PORT=1880
hostname: nodered1
networks:
mynetwork:
ipv4_address: 172.20.0.6
nodered2:
image: nodered/node-red-docker
ports:
- "1881:1880"
restart: always
environment:
- TZ
- IP_BROKER=mqtt
- DOCKER=true
- PORT=1880
hostname: nodered2
networks:
mynetwork:
ipv4_address: 172.20.0.7
@f2ka07
Copy link

f2ka07 commented Apr 16, 2023

This works great. It is a good way to use Docker Compose for Static/fixed IP . An alternative option would be to use container names instead of IP Addresses.

My container network has Nginx Reverse Proxy Manager with IP address 10, Portainer Docker Compose with IP Address 11, and finally WorPress MYSQL Docker Compose with IP Address 9 and 8 respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment