【问题标题】:No EXPOSE in aws docker fails deploymentaws docker 中没有 EXPOSE 部署失败
【发布时间】:2015-09-02 14:11:27
【问题描述】:

我有一个scrapy项目,由托管在 docker 映像中的 cron 持续运行。

当我在本地运行和部署它时,一切正常。如果我尝试将其部署到 AWS,我会在日志中收到以下错误:

No EXPOSE directive found in Dockerfile, abort deployment (ElasticBeanstalk::ExternalInvocationError)

控制台显示我的容器已正确构建,但如果没有 EXPOSED 端口,我将无法使用它。

INFO: Successfully pulled python:2.7
WARN: Failed to build Docker image aws_beanstalk/staging-app, retrying...
INFO: Successfully built aws_beanstalk/staging-app
ERROR: No EXPOSE directive found in Dockerfile, abort deployment
ERROR: [Instance: i-6eebaeaf] Command failed on instance. Return code: 1 Output: No EXPOSE directive found in Dockerfile, abort deployment.
Hook /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].

但为什么不可能呢?

我的 Dockerfile 如下所示:

FROM python:2.7
MAINTAINER XDF

ENV DIRECTORY /opt/the-flat

# System
##########

RUN apt-get update -y && apt-get upgrade -y && apt-get install -y ntp vim apt-utils
WORKDIR $DIRECTORY

# GIT
##########
# http://stackoverflow.com/questions/23391839/clone-private-git-repo-with-dockerfile

RUN apt-get install -y git
RUN mkdir /root/.ssh/
ADD deploy/git-deply-key /root/.ssh/id_rsa
RUN chmod 0600 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan -t rsa bitbucket.org >> /root/.ssh/known_hosts
RUN ssh -T -o 'ConnectionAttempts=1' git@bitbucket.org
RUN git clone --verbose git@bitbucket.org:XDF/the-flat.git .

# Install
##########

RUN pip install scrapy
RUN pip install MySQL-python

# not working
# apt-get install -y wkhtmltopdf && pip install pdfkit
# else
# https://pypi.python.org/pypi/pdfkit

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openssl build-essential xorg libssl-dev
RUN wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2
RUN tar xvjf wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2
RUN chown root:root wkhtmltopdf-amd64
RUN mv wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf
RUN pip install pdfkit

# Cron
##########
# http://www.ekito.fr/people/run-a-cron-job-with-docker/
# http://www.corntab.com/pages/crontab-gui

RUN apt-get install -y cron
RUN crontab "${DIRECTORY}/deploy/crontab"

CMD ["cron", "-f"]

【问题讨论】:

    标签: python amazon-web-services amazon-elastic-beanstalk dockerfile


    【解决方案1】:

    这是设计使然。你需要在你的 Dockerfile 中有一个 EXPOSE 端口指令来告诉 beanstalk 你的应用程序将监听哪个端口。您是否有不能或不想在 Dockerfile 中使用 EXPOSE 的用例?

    【讨论】:

    • 很遗憾,我的scrapy爬虫只是获取数据并将其存储到数据库中。所以不需要曝光。现在我只是暴露了一个随机端口并且它工作了..但是为什么需要它?
    • 通常这适用于结构化为 Web 应用程序的应用程序。工作层也被构建为 Web 应用程序,即使端口仅在 localhost 上为工作层打开。
    • @RohitBanga 几年来,我们一直在 Elastic Beanstalk 中运行不公开端口的工作程序——它们连接到队列服务并处理消息。 EXPOSE 端口的要求对于 WORKER 层容器来说是愚蠢的。作为一种解决方法,我们必须公开一些端口,即使它不会被使用。
    • 它只暴露在本地主机上,因为工作层守护进程在你的容器之外运行。
    【解决方案2】:

    ElasticBeanstalk 是为 Web 应用程序设计的,因此需要 EXPOSE。您演示的用例是作业(工作者)服务器,Elastic Beanstalk 不能很好地处理该用例。
    对于您的情况,要么公开一个虚拟端口号,要么自己启动一个 EC2 实例以绕过 EB 过载。

    【讨论】:

    • 是否也有工作器(Cronjob)触发的实例类型?
    猜你喜欢
    • 2021-04-09
    • 2017-01-29
    • 2021-07-19
    • 2016-06-19
    • 2016-07-10
    • 2021-11-03
    • 2021-06-05
    • 2019-04-07
    • 1970-01-01
    相关资源
    最近更新 更多