docker - 从多个容器创建单个Docker镜像

标签 docker nginx flask docker-compose uwsgi

我对容器世界和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 组成文件的内容:
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时,我得到了多个镜像,我认为这不是理想的结果?我想我当时想这将是一个图像,然后可以将其移动并在其他位置运行。

但是问题是如何移动图像并在没有Internet访问的情况下在计算机上运行它们。

我能够在本地构建应用程序,并且一切工作顺利。

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

最佳答案

对于第一个问题,您的假设是错误的。没有“一幅图片”涵盖了组合中的所有服务。每个服务将具有其自己的图像。

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

关于docker - 从多个容器创建单个Docker镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60484895/

相关文章:

Docker-Compose 重启策略

python - 在 pycharm : "Remote path not provided" 中创建新的 django 项目

Docker - 限制挂载的卷大小

mysql - Docker 连接到数据库时出错 - 对许多其他网站使用 nginx、mysql 和虚拟主机

ruby-on-rails - 如何在同一个 ec2 实例中运行两个 unicorn 环境

python - 无法安装 flask-mongoengine

python - uwsgi + nginx + flask : upstream prematurely closed

ubuntu - 在 Ubuntu 11.04 上安装 Nginx 1.0.5 时如何使用 Puppet 依赖项

python - Google App Engine URL 处理程序运行时出错

python - Flask Assets 仅在一个文件中查找更改