dockerfile - cpan proxy configuration

109 Views Asked by At

I am creating a docker image via dockerfile.

...
RUN dnf install -y cpan perl perl-core perl-App-cpanminus make
RUN cpan Config::Properties
...

I require to install a CPAN library (Config::Properties) but my system is behind the proxy and therefore system is unable to install it.

Fetching with HTTP::Tiny:
http://www.cpan.org/authors/01mailrc.txt.gz
HTTP::Tiny failed with an internal error: Could not connect to 'www.cpan.org:80': Connection timed out

I found that this can be fixed by configuring a proxy for CPAN, like (https://stackoverflow.com/a/46859266/1690588)

$ cpan  # to open cpan shell
  cpan[1]> o conf http_proxy "host:port"
  cpan[2]> o conf commit
  cpan[3]> q

BUT how can I do this inside dockerfile. Please suggest. Thank you!

1

There are 1 best solutions below

0
MKB On BEST ANSWER

Not able to find a solution. So I added a hack to achieve this -

  • performed the same operation on my host machine (installed cpan)

  • copy cpan configuration file from host /root/.cpan/CPAN/MyConfig.pm

  • and pasted in parallel to my Dockerfile

  • then added code in my Dockerfile to copy this file into the image so that I can fix the above issue

    ...
    RUN cpan
    COPY MyConfig.pm /root/.cpan/CPAN/MyConfig.pm
    RUN cpan Config::Properties
    ...