【问题标题】:Create single docker image from multiple containers从多个容器创建单个 docker 映像
【发布时间】:2020-06-14 12:22:52
【问题描述】:

我对容器世界和 docker 非常陌生,但由于我正在从事的项目的特定基础架构限制,我觉得它是我需要利用的技术。

我正在尝试在我的 Windows 10 机器上构建我的应用程序,然后将其迁移到另一台 Windows 10 计算机上,该计算机位于另一个无法访问互联网且没有通信的网络上(我只能从我的主网络)。该应用程序是在 uWsgi/nginx 服务器上运行的 Flask 应用程序。

我遵循了一些关于 docker 和 docker compose 的教程,并提出了以下应用程序结构:

Application
    - flask
        - app
        - env
        - Dockerfile
        - app.config
        - run.py
    - nginx
        - Dockerfile
        - nginx.conf
    - docker-compose.yml

docker compose 文件的内容:

version: "3.7"

services:

  nginx:
    build: ./nginx
    image: nginx
    container_name: nginx
    restart: always
    ports:
      - "80:80"
      - "443:443"

  flask:
    build: ./flask
    container_name: flask
    restart: always
    image: trac
    environment:
      - APP_NAME=Trac
    expose:
      - 8080
    depends_on:
      - nginx

flask Dockerfile 的内容:

# Use python 3.7 container image
FROM python:3.7.2-stretch

# Set the working directory of the app
WORKDIR  /app

# Copy the directory contents into the container at /app
ADD . /app

# Install the dependencies
RUN pip install -r requirements.txt

# run the command to start uWSGI 
CMD ["uwsgi", "app.ini"]

app.ini 的内容

[uwsgi]
wsgi-file = run.py
callable = app
socket = :8080
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true

nginx Dockerfile 的内容: 来自 nginx

RUN rm /etc/nginx/conf.d/default.conf


COPY crt.crt /etc/nginx/
COPY key.key /etc/nginx/

COPY nginx.conf /etc/nginx/conf.d

nginx.conf 的内容

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    listen 443 ssl http2 default_server;
    ssl_certificate crt.crt;
    ssl_certificate_key key.key;
    location / {
        include uwsgi_params;
        uwsgi_pass flask:8080;
    }
}

当使用 docker-compose build 时,我构建了多个我认为不会是预期结果的图像?我想我在想这将是一个单一的图像,然后可以移动并在其他地方运行。

但问题是如何移动图像并在没有互联网访问的计算机上运行它们。

我能够在本地构建应用程序并且一切正常。

对此的任何帮助都会很棒。提前致谢。

【问题讨论】:

  • running them on the computer with no internet access. 上面安装了 docker 吗?
  • 是的。我在那台机器上安装了 Docker Desktop for Windows。

标签: docker nginx flask docker-compose uwsgi


【解决方案1】:

对于您的第一个问题,您的假设是错误的。没有“一个图像”可以涵盖撰写中的所有服务。每个服务都有自己的图像。

对于没有互联网问题的分发...您可以使用本地注册表,您之前已在其中加载了您拥有的所有基本依赖项(python、nginx 容器...)。

【讨论】:

  • 我只是在尝试这个,我似乎无法从没有网络的计算机上完成本地注册表,因为它正在寻找互联网连接。我已通过问题进行了更新,以说明计算机位于另一个网络上,并且无法通过该网络进行通信。我只能从我的网络推/拉到它。
【解决方案2】:

不是我会推荐它,但是您可以创建单个 docker 映像,所有服务都在容器内运行,例如 GitLab docker 发行版也是如此(它运行所有服务 -- nginx , app, postgres, ... -- 在单个图像中)。您只需在单个容器中自己配置所有服务,这可能很乏味,但可行。

还有一个 docker-in-docker 镜像,您可以使用该镜像来运行您的 docker-compose 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多