Advertisement
otakana

Untitled

Mar 26th, 2022
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | None | 0 0
  1. Ensure a hosts entry for a docker container running as a systemd service.
  2. I'm going to hell :/
  3. if you're *not* running in a user context, you don't need the container priv esc to overwrite the hosts file.
  4.  
  5. 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"
  6.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement