omniedgeio / omniedge

Bringing intranet on the internet with Zero-Config Mesh VPNs.
https://omniedge.io
GNU General Public License v3.0
865 stars 50 forks source link

IP address changes on container restart #62

Closed mqt2r closed 1 year ago

mqt2r commented 1 year ago

Every time I restart omniedge container, the IP address changes.

docker-compose file:

version: "2.1"
services:
  omniedge:
    image: omniedge/omniedge:latest
    container_name: omniedge
    hostname: fixedname
    privileged: true
    network_mode: host
    restart: unless-stopped
    environment:
      - OMNIEDGE_SECURITYKEY=xxxx
      - OMNIEDGE_VIRUTALNETWORK_ID=xxxx
    volumes:
      - /dev/net/tun:/dev/net/tun
    cap_add:
      - net_admin

docker version:

Client: Docker Engine - Community
 Version:           20.10.22
 API version:       1.41
 Go version:        go1.18.9
 Git commit:        3a2c30b
 Built:             Thu Dec 15 22:28:22 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.22
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.9
  Git commit:       42c8b31
  Built:            Thu Dec 15 22:26:14 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.13
  GitCommit:        78f51771157abb6c9ed224c22013cdf09962315d
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

I expect the IP address of the container to remain the same after a restart.

Yong-OmniEdge commented 1 year ago

The problem is from the command cp /proc/sys/kernel/random/uuid /etc/machine-id, which will generate new uuid after a restart. You can change your dockerfile and change it to a fixed uuid. Here is the script: https://github.com/omniedgeio/omniedge-docker/blob/main/entrypoint