Ensure a hosts entry for a docker container running as a systemd service. I'm going to hell :/ if you're *not* running in a user context, you don't need the container priv esc to overwrite the hosts file. ExecStartPost=/bin/bash -c "( flock 9 || exit 1;until [ \"\$(docker inspect -f {{.State.Running}} %n )\" == \"true\" ]; do sleep 0.1; done; grep -v '%n' /etc/hosts > /tmp/tmphosts && echo \"\$( docker inspect -f '{{.NetworkSettings.IPAddress }}' %n ) %n #autogenerated\" >> /tmp/tmphosts && docker run --rm -v/tmp/tmphosts:/tmp/tmphosts -v/etc/hosts:/etc/hosts alpine sh -c 'cat /tmp/tmphosts > /etc/hosts' ) 9> /tmp/tmphosts.lock"