add hostname mappings using –add-host parameter not working for scratch image

Add hostname mappings using the --add-host parameter is not working for a scratch image.

I configure it as following:

extra_hosts:
  - "op.swish-cloud.com:10.170.0.2"

But the actual id of requests from the container is the external internet ip of op.swish-cloud.com rather than 10.170.0.2

Source: StackOverflow