Allow hostname in PeerAddress entries?


#1

Is there some reason we can’t specify a hostname instead of an IP for the PeerAddress entries in the config file? If the reason is just that it hasn’t been done, is there any reason I shouldn’t log a feature request?

I’m struggling with this same issue of the IP changing each time described in this thread, but docker doesn’t allow static IPs when running in swarm mode.

I modified the above solution from @kvaps at the end of that thread to try to do the same thing, since it seems like a sensible workaround; unfortunately, I can’t see how to get the container IP in the docker compose file. I tried this:

command: [ '/bin/sh', '-c', 'IP=$$(hostname -i); sed -i "/PeerAddress/ s/: .*/: \"$IP\",/g" /root/.config/pydio/cells/pydio.json; exec /bin/docker-entrypoint.sh cells start']

…but hostname -i always resolves to 127.0.0.1, which doesn’t work.


#2

Hi Geoff, i think the link may be to the wrong thread.

does ifconfig work for you in the container?


#3

Thanks Ross - I fixed the link.

So, yes, I do get valid values in the container, and also once I’m in that context I do get a valid result from hostname -i; I also just figured out that the 127.0.0.1 is coming from a local environment variable, so there’s something else wrong with my shell line (not surprising!)

/pydio # ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:0A:00:01:80
          inet addr:10.0.1.128  Bcast:10.0.1.255  Mask:255.255.255.0
          [...]
eth1      Link encap:Ethernet  HWaddr 02:42:AC:14:00:07
          inet addr:172.20.0.7  Bcast:172.20.255.255  Mask:255.255.0.0
          [...]
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0

/pydio # hostname -i
10.0.1.128

When I remove the environment variable, and one of the ‘$’ signs, I end up with this:

command: [ '/bin/sh', '-c', 'IP=$(hostname -i); sed -i "/PeerAddress/ s/: .*/: \"$IP\",/g" /root/.config/pydio/cells/pydio.json; exec /bin/docker-entrypoint.sh cells start']

…resolving to this:

Maybe it’s just a bad shell line? Or perhaps the hostname command doesn’t resolve at that early stage?


#4

it looks like the subshell you are using does get run on the host not the container, see here: https://serverfault.com/questions/782967/docker-exec-run-shell-command-nesting


#5

maybe using xargs or something might get what you want? or maybe backtics?


#6

Ross, thanks so much for the tip on the backticks, my shell knowledge is still so basic!

Once I had that I still needed to find a command that would happily sit in the overall command line - generally it seems quite tricky to work around the constraints of the docker compose format. For example, nested quotes are hard to work around, and dollar signs seem to be problematic.

I noticed that the last entry in hosts is for the container, so in combination with your backticks suggstion I managed to put together a command that extracts this without any quotes or dollar signs:

echo `tail -1 /etc/hosts | cut -f 1` > /home/ip.txt

Then, embedding that into my overall command line:

command: [ '/bin/sh', '-c', 'echo `tail -1 /etc/hosts | cut -f 1` > /home/ip.txt; sed -i "/PeerAddress/ s/: .*/: \"`cat /home/ip.txt`\",/g" /root/.config/pydio/cells/pydio.json; exec /bin/docker-entrypoint.sh cells start' ]

…which in turn gives me a correct IP:

"pydio.grpc.data.index.personal": {
  "PeerAddress": "10.0.1.235",
  "dsn": "default",

Thanks again! I’d still really like to be able to use the hostname in the file in the first place, so I have logged a feature request for this.

Cheers,
Geoff