【问题标题】:Cannot build dockerfile due to port restrictions由于端口限制,无法构建 dockerfile
【发布时间】:2019-12-22 21:47:11
【问题描述】:

我在企业互联网上。我们只能使用某些端口/通过代理连接。

我正在尝试运行以下简单的 docker 命令:

docker build -t MY_USERNAME/myfirstapp .

我的 dockerfile 包含这个:

# our base image
FROM alpine:3.5

# Install python and pip
**RUN apk add --update py2-pip**

# install Python modules needed by the Python app
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt

# copy files required for the app to run
COPY app.py /usr/src/app/
COPY templates/index.html /usr/src/app/templates/

# tell the port number the container should expose
EXPOSE 5000

# run the application
CMD ["python", "/usr/src/app/app.py"]

它在RUN apk add --update py2-pip 上失败并出现错误

fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.c51f8f92.tar.gz: No such file or directory

我可以从 curl 这个地址中看出它可以工作,所以这一定是代理/端口问题。

如何在遵守端口/代理限制的情况下执行此操作?

非常感谢。

【问题讨论】:

    标签: docker ubuntu ubuntu-16.04 alpine docker-build


    【解决方案1】:
    docker build --network=host -t MY_USERNAME/myfirstapp .
    

    工作:)。

    【讨论】:

      【解决方案2】:

      您可以使用代理设置,如

      docker build --build-arg http_proxy=http://x.x.x.x:y --build-arg https_proxy=http://x.x.x.x:y -t MY_USERNAME/myfirstapp .

      我总是推荐使用docker-compose,因为这是定义构建参数或运行容器、映射卷、端口等的标准化方式。 在 docker-compose.yaml 中,代理定义如下所示:

      version: '3'
      services:
        main:
          build:
              context: .
              args:
                  - http_proxy
                  - https_proxy
                  - no_proxy
          image: MY_USERNAME/myfirstapp
      

      使用此配置,您将通过在您的主机系统上定义的三个代理设置的定义。 在 docker-compose.yaml 所在的目录中使用 docker-compose build 调用 docker-compose 很容易。

      【讨论】:

        猜你喜欢
        • 2017-12-04
        • 2019-10-19
        • 2022-12-11
        • 2017-07-15
        • 2018-07-06
        • 1970-01-01
        • 2019-10-29
        • 2021-04-18
        • 1970-01-01
        相关资源
        最近更新 更多