Allow hostname in PeerAddress entries?


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/ cells start']

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


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

does ifconfig work for you in the container?


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 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:  Bcast:  Mask:
eth1      Link encap:Ethernet  HWaddr 02:42:AC:14:00:07
          inet addr:  Bcast:  Mask:
lo        Link encap:Local Loopback
          inet addr:  Mask:

/pydio # hostname -i

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/ 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?


it looks like the subshell you are using does get run on the host not the container, see here:


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


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/ cells start' ]

…which in turn gives me a correct IP:

"": {
  "PeerAddress": "",
  "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.