Based on what you have mentioned in your query, I assume that you have written a Dockerfile for your python application and have created a container as well.
Now here is what what you can try to set the DNS address for your python application.
Try changing the DNS settings of the Docker daemon. You can edit (or create) the configuration file at /etc/docker/daemon.json with the dns key, as following:
{
"dns": ["your_dns_address", "8.8.8.8"]
}
In the above command, the first element of the list is the address of your DNS server. The second item is the Google’s DNS which can be used when the first one is not available.
Before moving ahead, save daemon.json and restart the docker service by typing below commands::
sudo service docker restart
Once you think the DNS problem is fixed, retry to run the build command.
I hope that the above information will resolve your query.