Systemd Service Start With Dynamic Port Value From Docker
Solution 1:
The systemd ExecStart
option doesn't do any shell interpolation and thus doesn't understand stuff like $(echo 'Hello')
. But, you can start a shell that executes the command to get behavior like this. Try something like:
ExecStartPost=/bin/sh -c "/usr/bin/etcdctl set /services/myServiceName '{ \"host\": \"%H\", \"port\": '$(echo $(/usr/bin/docker port my-container-name 5555) | cut -d':' -f2)'}'"