gpt4 book ai didi

docker - 无法在远程主机上构建 docker 容器

转载 作者:行者123 更新时间:2023-12-01 15:36:15 24 4
gpt4 key购买 nike

我有一组从 yml 文件生成的 docker 容器并且工作正常。

我现在想将它们部署到另一台机器上。在另一篇文章中here我被建议使用 2 个选项之一在远程主机上构建容器:

  • 选项 1 - 将代码复制到远程主机并应用修改后的 docker-compose,并使用修改后的 docker-compose 从源代码构建

  • 选项 2 - 在本地机器上创建一个图像,将其推送到 docker 存储库,然后使用修改后的 docker-compose 从那里拉取它

我正在尝试遵循选项 1(作为开始)。我将代码复制到远程主机,并修改了 Dockerfile 和 docker-compose.yml 文件 (snippet1)

构建进行到一半。它下载 python 和 postgres 图像,并开始处理 Dockerfile,但它无法安装要求(它无法安装第一个要求 - 请参阅片段 2)

可能是什么问题?

snippet1 - Dockerfile.dair 和 docker-compose.yml

cat /home/ubuntu/webServer/web/Dockerfile.dair

FROM python:3.6.1
MAINTAINER User4 <user4@gmail.com>

# Create the group and user to be used in this container
RUN groupadd flaskgroup && useradd -m -g flaskgroup -s /bin/bash flask

# Create the working directory (and set it as the working directory)
RUN mkdir -p /home/flask/app/web
WORKDIR /home/flask/app/web

# Install the package dependencies (this step is separated
# from copying all the source code to avoid having to
# re-install all python packages defined in requirements2.txt
# whenever any source code change is made)
COPY requirements2.txt /home/flask/app/web
RUN pip install --no-cache-dir -r requirements2.txt

# Copy the source code into the container
COPY . /home/flask/app/web

RUN chown -R flask:flaskgroup /home/flask

USER flask

EXPOSE 8000

CMD /usr/local/bin/gunicorn -w 2 -t 3600 -b :8000 project:app

ENV PYTHONUNBUFFERED=1
ENV FLASK_APP=run.py
ENV FLASK_DEBUG=1

,

cat /home/ubuntu/construction_overlay/webServer/docker-compose.dair.yml
version: '3'

services:
web:
restart: always
build:
context: ./web
dockerfile: Dockerfile.dair
volumes:
- /home/ubuntu/construction_overlay/webServer/web:/home/flask/app/web
depends_on:
- postgres

nginx:
restart: always
build: ./nginx
ports:
- "80:80"
volumes:
- /home/ubuntu/construction_overlay/webServer/web:/home/flask/app/web
depends_on:
- web

postgres:
restart: always
build: ./postgresql
volumes:
- data1:/var/lib/postgresql
expose:
- "5432"

volumes:
data1:

snippet2 - 构建未能安装要求

cat /home/ubuntu/webServer/web/requirements.txt
alembic==0.8.8
atomicwrites==1.3.0
attrs==19.1.0
...

,

docker-compose -f /home/ubuntu/webServer/docker-compose.dair.yml  up --build -d;
Building postgres
Step 1/4 : FROM postgres:11.3
---> 4e045cb8eecd
Step 2/4 : ENV POSTGRES_USER postgres_user
---> Using cache
---> 400023c58607
Step 3/4 : ENV POSTGRES_PASSWORD postgres_user
---> Using cache
---> 0cf91f314380
Step 4/4 : ENV POSTGRES_DB construction-overlay-db
---> Using cache
---> 151106ecf13b
Successfully built 151106ecf13b
Successfully tagged webserver_postgres:latest
Building web
Step 1/10 : FROM python:3.6.1
---> 955d0c3b1bb2
Step 2/10 : MAINTAINER User4 <user4@gmail.com>
---> Using cache
---> 128d55ddb4e7
Step 3/10 : RUN groupadd flaskgroup && useradd -m -g flaskgroup -s /bin/bash flask
---> Using cache
---> e2c30915fcf5
Step 4/10 : RUN mkdir -p /home/flask/app/web
---> Using cache
---> 8f44dada5953
Step 5/10 : WORKDIR /home/flask/app/web
---> Using cache
---> 04a895c3fe27
Step 6/10 : COPY requirements.txt /home/flask/app/web
---> Using cache
---> 13ab37e789f8
Step 7/10 : RUN pip install --no-cache-dir -r requirements.txt
---> Running in 61475950cd73
Collecting alembic==0.8.8 (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f1e979262b0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/alembic/

最佳答案

解决方案是在云提供商处为 UDP 出站添加规则添加这条规则后,前置要求安装ok

Egress  IPv4    UDP     1 - 65535   0.0.0.0/0 

关于docker - 无法在远程主机上构建 docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57660643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com