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

时间:2019-08-26 15:14:35

标签: docker docker-compose

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

我现在想将它们部署到另一台计算机上。在另一篇here中,建议我使用以下两个选项之一在远程主机上构建容器:

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

  • 选项2-使用修改后的docker-compose

  • 在本地计算机上创建映像,将其推送到docker存储库,从那里拉出图像

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

构建进行到一半。它会下载python和postgres映像,并开始处理Dockerfile,但无法安装要求(无法安装第一个要求-参见snippet2)

可能是什么问题?

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/

1 个答案:

答案 0 :(得分:1)

解决方案是在云提供商处添加UDP出站规则 添加此规则后,先安装ok

Egress  IPv4    UDP     1 - 65535   0.0.0.0/0