How to connect a network to build env?

The host cannot connect to Internet directly. But there is a container running as proxy on a specific network.

For a regular container, I just docker network connect proxy $contain. But when I build an image, how can I connect the network to it? And leaves nothing in the image (I mean it won’t connect to the network when running).