如何在公司代理后面构建Docker容器?

问题描述

我正在尝试构建一个基于python的简单docker容器。我在Windows 10上的一家代理公司背后工作。下面是我的docker文件

FROM python:3.7.9-alpine3.11

workdir ./

RUN pip install --proxy=http://XXXXXXX:8080 -r requirements.txt

copY . /

EXPOSE 5000
CMD ["python","application.py"]

但这给了我cmd中的以下错误

"Failed to solve with frontend dockerfile.v0: Failed to build LLB: Failed to load cache key: Failed to do request: Head https://registry-1.docker.io/v2/library/python/manifests/3.7.9-alpine3.11: proxyconnect tcp: EOF"

我尝试使用许多链接来弄清楚如何配置docker的代理,但是它们一直引用文件“ / etc / sysconfig / docker”,在Windows 10下我找不到它,或者也许我不在意正确的地方。

我也不知道这仅仅是一个代理问题,因为我看到有人在不使用代理的情况下遇到此问题。 我非常感谢任何人的帮助。在这家公司工作已经使我花了超过10个小时来做​​某事,而这些事情花了我10分钟才能在Mac上完成... :( 谢谢

解决方法

您正在谈论最基本的Docker功能。通常,它必须连接到互联网上的Docker Hub才能获取基本映像。如果您无法通过代理使用此功能,则可以

  1. 用必要的图像预加载本地缓存
  2. 在防火墙内设置一个Docker注册表,其中包含您需要的所有映像

很显然,到目前为止,最容易的事情是弄清楚如何使Docker通过代理连接到Docker Hub。

就让Windows上的Docker与您的代理一起使用而言,这可能有帮助吗? -https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/configure-docker-daemon

这是有关配置代理的内容:

To set proxy information for docker search and docker pull,create a Windows environment variable with the name HTTP_PROXY or HTTPS_PROXY,and a value of the proxy information. This can be completed with PowerShell using a command similar to this:

In PowerShell:

    [Environment]::SetEnvironmentVariable("HTTP_PROXY","http://username:password@proxy:port/",[EnvironmentVariableTarget]::Machine)

Once the variable has been set,restart the Docker service.

In PowerShell: 

    Restart-Service docker

For more information,see Windows Configuration File on Docker.com.

我还看到它提到 Docker for Windows 允许您在其配置GUI界面中设置代理参数。

,

无需在 Dockerfile 中传递代理信息。

有可用于此目的的预定义 ARG。 HTTP_PROXY HTTPS_PROXY FTP_PROXY

您可以在构建图像时传递详细信息

https://docs.docker.com/engine/reference/builder/#predefined-args

我在 Internet 上没有看到您的容器有任何运行时依赖性。因此,运行容器将没有问题。