I'm new to CoreOS and Docker and I'm facing with a problem with fleet.
I have a standard unit launching a POSTGRES container and I would like to know the IP address of the machine where this unit is started. I have actually a cluster of 3 machines and the POSTGRES unit isn't always started on the same machine (which means the IP is not static).
I need it when I start another unit (see below), which needs a POSTGRES.
I'm using at the moment the Unit Parameter called BindsTo :
[Unit]
Description=Test
After=docker.service
After=postgres@1.service
Requires=docker.service
Requires=postgres@1.service
BindsTo=postgres@1.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill test%i
ExecStartPre=-/usr/bin/docker rm test%i
ExecStart=/usr/bin/docker run -rm --name test%i -e HOST="HereThePostgresIP" sryther/test
ExecStop=/usr/bin/docker stop test%i
N.B. : This unit doesn't need to be started on the same machine as the POSTGRES unit.
I tried with %H variable but it returns the hostname and not the IP address of the machine.
Flannel is also used in my cluster.
Thanks!
I found a workaround :
[Unit]
Description=Test
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill test%i
ExecStartPre=-/usr/bin/docker rm test%i
ExecStart=/usr/bin/docker run -rm --name test%i --link postgres1:postgres sryther/test
ExecStop=/usr/bin/docker stop test%i
And the IP address is set in the container environment as POSTGRES_PORT_5432_TCP_ADDR.