Getting connection timed out while installing Jenkins plugins through Dockerfile

I am trying to install Jenkins 2.393 version through Dockerfile, I am getting an timed out error while trying to download Plugins. Can someone help me out? Please find the below Dockerfile and Attached error what I am getting. Error I am getting:

Unable to resolve plugin URL https://updates.jenkins.io/download/plugins/ansicolor/1.0.2/ansicolor.hpi, or download plugin ansicolor to file: Connect to ftp-chi.osuosl.org:443 [ftp-chi.osuosl.org/64.50.236.52] failed: Connection timed out (Connection timed out)
Tried downloading ansicolor from https://ftp-chi.osuosl.org/pub/jenkins/plugins/ansicolor/1.0.2/ansicolor.hpi (attempt 1 of 3)

Hello @Anurag and welcome to this community :wave:

Sometimes, I have the same error too, but most of the times, it is transient.
Your error message indicates that the connection to the Jenkins plugin repository at https://updates.jenkins.io is timing out. This can happen due to network issues, firewalls, or the server being overloaded.

To troubleshoot the issue, you can try the following steps:

  1. Verify that you can access the plugin repository URL https://updates.jenkins.io from your Docker container by running the curl command (while being in the container thanks to a docker exec -ti) for example:
$ curl -I https://updates.jenkins.io

If you see a response with HTTP status code 200, it means that you can access the plugin repository.
2. Check if there are any network issues that may be causing the timeout. You can try running the ping command to see if you can reach the plugin repository:

$ ping updates.jenkins.io

If you see a response from the server, it means that you can reach the server and there is no network issue.
3. If you are behind a firewall or proxy server, make sure that the Docker container is configured to use the appropriate proxy settings. You can set the proxy settings in the Dockerfile using the ENV command, for example:

ENV http_proxy http://your.proxy.server:port
ENV https_proxy http://your.proxy.server:port

Replace your.proxy.server and port with your actual proxy server and port number.
4. Another option is to pre-install the required plugins in the Docker image. You can download the plugins manually from the Jenkins plugin repository and copy them to the Docker image using the COPY command in the Dockerfile. For example:

COPY plugins/ansicolor.hpi /usr/share/jenkins/ref/plugins/

Replace plugins/ansicolor.hpi with the path to the downloaded plugin file, and make sure to update the plugin list in the plugins.txt file.