Everything

使用代理为docker-compose加速

by Mion, 2021-09-11


在生产环境中经常会使用docker-compose来部署项目,由于众所周知的原因,在国内网络环境中下载部分托管在第三方平台的docker镜像会有下载缓慢的问题。下面将介绍快速使用代理为docker-compose加速。

.env 文件

Docker文档中提到Docker-compose支持加载当前工作目录下的.env文件,原文如下:

Compose supports declaring default environment variables in an environment file named .env placed in the project directory. Docker Compose versions earlier than 1.28, load the .env file from the current working directory, where the command is executed, or from the project directory if this is explicitly set with the --project-directory option. This inconsistency has been addressed starting with +v1.28 by limiting the default .env file path to the project directory. You can use the --env-file commandline option to override the default .env and specify the path to a custom environment file.

综上,我们在与docker-compose.yml同目录下创建.env文件:

HTTP_PROXY=proxy_url:port //例 HTTP_PROXY=127.0.0.1:1080
HTTPS_PROXY=proxy_url:port
FTP_PROXY=proxy_url:port
NO_PROXY=no_proxy_url

然后再运行docker-compose up即可。

docker-compose

作者: Mion

2022 © Mion'Blog & Theme By xingr