1

我使用 Docker 和 cookiecutter-django 在本地开发。

Cookiecutter-django 在“compose”目录中创建了几个 Dockerfile。

我现在正试图将项目推送到 Heroku。
不过,heroku container:push web会回来No images to push的。

如果我在 compose 目录的子目录中尝试相同的命令,它最终会中断——可能是由于尝试仅推送部分 dockerfile。

如何利用 Heroku 容器在 Heroku 上启动并运行它?

Heroku 的这篇文章说我可以通过重命名 Dockerfile 来推送多个图像,但我不确定如何确定这些 cookiecutter 生成的 Dockerfile 中的哪些属于哪种进程类型。

docker images将返回:

REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
<none>                                        <none>              16e570f295a7        10 minutes ago      318MB
luup_celeryworker                           latest              bd7ff7e5eb10        2 hours ago         531MB
luup_django                                 latest              bd7ff7e5eb10        2 hours ago         531MB
luup_celerybeat                             latest              bd7ff7e5eb10        2 hours ago         531MB
luup_postgres                               latest              e50eb7b8a704        2 hours ago         287MB
registry.heroku.com/fierce-forest-57627/web   latest              27690b3e49d4        16 hours ago        766MB
python                                        3.6-alpine          c3a4a35c9244        22 hours ago        90MB

这是cookiecutter制作的Dockerfile。它是compose/production/django下的DF。还有其他 DF——用于 caddy、postgres 以及用于本地的 DF。

FROM python:3.6-alpine

ENV PYTHONUNBUFFERED 1

RUN apk update \
  # psycopg2 dependencies
  && apk add --virtual build-deps gcc python3-dev musl-dev \
  && apk add postgresql-dev \
  # Pillow dependencies
  && apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
  # CFFI dependencies
  && apk add libffi-dev openssl-dev py-cffi

RUN addgroup -S django \
    && adduser -S -G django django

# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./requirements /requirements
RUN pip install --no-cache-dir -r /requirements/production.txt \
    && rm -rf /requirements

COPY ./compose/production/django/gunicorn.sh /gunicorn.sh
RUN sed -i 's/\r//' /gunicorn.sh
RUN chmod +x /gunicorn.sh
RUN chown django /gunicorn.sh

COPY ./compose/production/django/entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r//' /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chown django /entrypoint.sh

COPY ./compose/production/django/celery/worker/start.sh /start-celeryworker.sh
RUN sed -i 's/\r//' /start-celeryworker.sh
RUN chmod +x /start-celeryworker.sh

COPY ./compose/production/django/celery/beat/start.sh /start-celerybeat.sh
RUN sed -i 's/\r//' /start-celerybeat.sh
RUN chmod +x /start-celerybeat.sh

COPY . /app

RUN chown -R django /app

USER django

WORKDIR /app

ENTRYPOINT ["/entrypoint.sh"]

如果您需要更多信息,请告诉我

编辑——添加树:

注意:我已按照 Heroku此处的指示将 Dockerfiles 重命名为 Dockerfile.processtype ——尽管我不再推送多个图像。正如您在树中看到的那样,我还移动了 Dockerfile.django 的副本和Dockerfile.local 到项目的根目录,因为这是它需要的位置Heroku container:push processtype --recursive

├── Dockerfile.django
├── Dockerfile.local
├── LICENSE
├── Procfile
├── README.rst
├── compose
│   ├── local
│   │   └── django
│   │       ├── celery
│   │       │   ├── beat
│   │       │   │   └── start.sh
│   │       │   └── worker
│   │       │       └── start.sh
│   │       └── start.sh
│   └── production
│       ├── caddy
│       │   ├── Caddyfile
│       │   └── Dockerfile.caddy
│       ├── django
│       │   ├── Dockerfile.django
│       │   ├── celery
│       │   │   ├── beat
│       │   │   │   └── start.sh
│       │   │   └── worker
│       │   │       └── start.sh
│       │   ├── entrypoint.sh
│       │   └── gunicorn.sh
│       └── postgres
│           ├── Dockerfile.postgres
│           └── maintenance
│               ├── _sourced
│               │   ├── constants.sh
│               │   ├── countdown.sh
│               │   ├── messages.sh
│               │   └── yes_no.sh
│               ├── backup
│               ├── backups
│               └── restore
├── config
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-35.pyc
│   │   ├── __init__.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   └── wsgi.cpython-36.pyc
│   ├── settings
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   ├── __init__.cpython-36.pyc
│   │   │   ├── base.cpython-35.pyc
│   │   │   ├── base.cpython-36.pyc
│   │   │   ├── local.cpython-35.pyc
│   │   │   ├── local.cpython-36.pyc
│   │   │   └── production.cpython-36.pyc
│   │   ├── base.py
│   │   ├── local.py
│   │   ├── production.py
│   │   └── test.py
│   ├── urls.py
│   └── wsgi.py
├── docs
│   ├── Makefile
│   ├── __init__.py
│   ├── conf.py
│   ├── deploy.rst
│   ├── docker_ec2.rst
│   ├── index.rst
│   ├── install.rst
│   └── make.bat
├── heroku.yml
├── local.yml
├── locale
│   └── README.rst
├── lurnup
│   ├── __init__.py
│   ├── __pycache__
│   │   └── __init__.cpython-36.pyc
│   ├── contrib
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   └── __init__.cpython-36.pyc
│   │   └── sites
│   │       ├── __init__.py
│   │       ├── __pycache__
│   │       │   └── __init__.cpython-36.pyc
│   │       └── migrations
│   │           ├── 0001_initial.py
│   │           ├── 0002_alter_domain_unique.py
│   │           ├── 0003_set_site_domain_and_name.py
│   │           ├── __init__.py
│   │           └── __pycache__
│   │               ├── 0001_initial.cpython-36.pyc
│   │               ├── 0002_alter_domain_unique.cpython-36.pyc
│   │               ├── 0003_set_site_domain_and_name.cpython-36.pyc
│   │               └── __init__.cpython-36.pyc
│   ├── static
│   │   ├── css
│   │   │   └── project.css
│   │   ├── fonts
│   │   ├── images
│   │   │   └── favicon.ico
│   │   ├── js
│   │   │   └── project.js
│   │   └── sass
│   │       ├── custom_bootstrap_vars.scss
│   │       └── project.scss
│   ├── taskapp
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-36.pyc
│   │   │   └── celery.cpython-36.pyc
│   │   └── celery.py
│   ├── templates
│   │   ├── 403_csrf.html
│   │   ├── 404.html
│   │   ├── 500.html
│   │   ├── account
│   │   │   ├── account_inactive.html
│   │   │   ├── base.html
│   │   │   ├── email.html
│   │   │   ├── email_confirm.html
│   │   │   ├── login.html
│   │   │   ├── logout.html
│   │   │   ├── password_change.html
│   │   │   ├── password_reset.html
│   │   │   ├── password_reset_done.html
│   │   │   ├── password_reset_from_key.html
│   │   │   ├── password_reset_from_key_done.html
│   │   │   ├── password_set.html
│   │   │   ├── signup.html
│   │   │   ├── signup_closed.html
│   │   │   ├── verification_sent.html
│   │   │   └── verified_email_required.html
│   │   ├── base.html
│   │   ├── pages
│   │   │   ├── about.html
│   │   │   └── home.html
│   │   └── users
│   │       ├── user_detail.html
│   │       ├── user_form.html
│   │       └── user_list.html
│   └── users
│       ├── __init__.py
│       ├── __pycache__
│       │   ├── __init__.cpython-36.pyc
│       │   ├── adapters.cpython-36.pyc
│       │   ├── admin.cpython-36.pyc
│       │   ├── apps.cpython-36.pyc
│       │   ├── models.cpython-36.pyc
│       │   ├── urls.cpython-36.pyc
│       │   └── views.cpython-36.pyc
│       ├── adapters.py
│       ├── admin.py
│       ├── apps.py
│       ├── migrations
│       │   ├── 0001_initial.py
│       │   ├── __init__.py
│       │   └── __pycache__
│       │       ├── 0001_initial.cpython-36.pyc
│       │       └── __init__.cpython-36.pyc
│       ├── models.py
│       ├── tests
│       │   ├── __init__.py
│       │   ├── factories.py
│       │   ├── test_admin.py
│       │   ├── test_models.py
│       │   ├── test_urls.py
│       │   └── test_views.py
│       ├── urls.py
│       └── views.py
├── manage.py
├── merge_production_dotenvs_in_dotenv.py
├── production.yml
├── pytest.ini
├── requirements
│   ├── base.txt
│   ├── local.txt
│   └── production.txt
4

1 回答 1

0

Cookiecutter-django 提供了一个标准的 docker compose 配置,您可以推送多个具有完整 Docker 支持的托管服务。

然而,Heroku 支持 Docker有一些限制。例如,WSGI 服务器的端口被硬编码为 5000,Heroku 需要使用环境变量$PORT

这些在 cookiecutter-django 中没有考虑,所以你必须改变一些事情:

  • 我将从 compose/production/django 中的图像开始,忽略 DB(通过add-on 提供)和 Caddy(请参阅此处)。
  • 将Gunicorn 端口从更改5000$PORT
  • 可能不需要进入DATABASE_URLentrypoint.sh代码。
  • 最后但同样重要的是:创建一个heroku.yml文件以指向您要使用的 DF。
  • 使用 docker-compose,您可以重复使用相同的 Dockerfile 并更改入口点,但我认为 Heroku 不可行。您可能需要创建一个重复的 web Dockerfile 并为您的 Celery dynos 更改它。

我在 Heroku 上尝试过 Docker,但没有使用 cookiecutter-django 设置。Heroku 方式在 IMO 中不够标准,它有点介于纯 Heroku 和裸 Docker 之间。

希望有帮助!

于 2018-03-24T12:12:49.080 回答