For security reasons, you need to be in privileged mode for this operation. It is not currently possible to use a Dockerfile with the privileged mode.
$> docker run ubuntu sysctl -w net.ipv4.route.flush=1 && echo ok || echo ko
sysctl: setting key "net.ipv4.route.flush": Read-only file system
ko
$> docker run --privileged ubuntu sysctl -w net.ipv4.route.flush=1 && echo ok || echo ko
ok
Why do you need to do this at build time?