Cannot use proxy in the docker container

I’m in China so I have to use proxy server to visit some service.
For example:

  • “APPs & Extensions” page in the password app.

  • Nginx timeout error occured almost every time when I open the APPs page, and then refresh it to get in, but it doesn’t load any application other than the enabled and disabled ones. Occasionally, I can load the APPs page, but I can’t install or update any application.

  • Cannot create a gmail account in the mail app.

  • Cannot subscribe some podcasts in the music app.

I tried three methods and all didn’t work.

  1. Add proxy config to www/nextcloud/config/config.php according to nextcloud official document;
  2. Add env “HTTP_PROXY” and “HTTPS_PROXY” to the container according to according to docker official document;
  3. Create a config.json in ~/.docker with proxy settings according to according to docker official document.

And for test, I tried wget www.google.com and I got:
wget: can't connect to remote host (199.96.58.177): Operation timed out.

And the method 2 above worked for me in the other container.

I‘m on CentOS 7.8.