otakana icon

Untitled

otakana | PRO | 03/26/22 10:34:33 AM UTC | 0 ⭐ | 1538 👁️ | Never ⏰ | []
Bash |

630 B

|

None

|

0 👍

/

0 👎

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"
 

Comments