Issue when yarn install inside docker, but works outside docker

I get this error

Yarn - There appears to be trouble with your network connection. Retrying

and then timeout as error An unexpected error occurred: 'https://registry.yarnpkg.com/<package name>.tgz: ESOCKETTIMEDOUT’.

I have tried adding network timeout via yarn install --network-timeout 240000 , still same issue

if have any suggestions for this then please let me know. Thankyou