如何在计算引擎实例上运行google appengine docker镜像?

时间:2015-06-04 14:20:38

标签: python google-app-engine google-compute-engine

我有以下docker文件:

<asp:ListView ID="lst1" runat="server">
  <ItemTemplate>
    <div style="width:<%#Eval("Rating")%>%">
    </div>
  </ItemTemplate>
</asp:ListView>

我创建了日志目录,否则我收到以下错误

FROM gcr.io/google_appengine/python-compat
MAINTAINER Me@me.com

RUN apt-get update
RUN apt-get -y upgrade

ADD ./app/ /app
ADD app.yaml /app/

RUN mkdir -p /var/log/app_engine

但现在我收到以下错误:

sudo docker run gcr.io/MY-PROJECT/ae-image
Traceback (most recent call last):
  File "/home/vmagent/python_vm_runtime/vmboot.py", line 133, in <module>
    run_file(__file__, globals())
  File "/home/vmagent/python_vm_runtime/vmboot.py", line 129, in run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/home/vmagent/python_vm_runtime/google/appengine/tools/vmboot.py", line 32, in <module>
    initialize.InitializeFileLogging()
  File "/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime/initialize.py", line 92, in InitializeFileLogging
    APP_LOG_FILE, maxBytes=MAX_LOG_BYTES, backupCount=LOG_BACKUP_COUNT)
  File "/usr/lib/python2.7/logging/handlers.py", line 117, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/handlers.py", line 64, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/__init__.py", line 901, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python2.7/logging/__init__.py", line 924, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 2] No such file or directory: '/var/log/app_engine/app.log.json'

我可以执行哪种配置或操作,以便在docker中运行此docker镜像,如:

sudo docker run -ti gcr.io/MY-PROJECT/ae-image /app/app.yaml
LOG 1 1433422040537094 Using module_yaml_path from argv: /app/app.yaml
Traceback (most recent call last):
  File "/home/vmagent/python_vm_runtime/vmboot.py", line 133, in <module>
    run_file(__file__, globals())
  File "/home/vmagent/python_vm_runtime/vmboot.py", line 129, in run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/home/vmagent/python_vm_runtime/google/appengine/tools/vmboot.py", line 65, in <module>
    main()
  File "/home/vmagent/python_vm_runtime/google/appengine/tools/vmboot.py", line 61, in main
    vmservice.CreateAndRunService(module_yaml_path)
  File "/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime/vmservice.py", line 154, in CreateAndRunService
    service.CreateServer()
  File "/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime/vmservice.py", line 126, in CreateServer
    appengine_config = vmconfig.BuildVmAppengineEnvConfig()
  File "/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime/vmconfig.py", line 60, in BuildVmAppengineEnvConfig
    _MetadataGetter('gae_backend_instance'))
  File "/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime/vmconfig.py", line 37, in _MetadataGetter
    return urllib2.urlopen(req).read()
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 407, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 520, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 445, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

我的另一个选择是在python中运行AE,但我不知道如何告诉它使用生产数据存储区(GCD)。我想这就是我在上面的docker实现中遇到的问题。

1 个答案:

答案 0 :(得分:8)

可以独立运行应用程序容器,但有一些细微差别。

卷绑定
首先,让我们看一下日志目录部分,您可以在其中创建/ var / log / appengine。当gcloud preview app run作用于容器时,它实际上使用卷绑定运行它,将容器中的/ var / log / appengine映射到主机上的/ var / log / appengine /(〜其他路径〜)。如果您正在使用boot2docker,则可以运行boot2docker ssh并在那里查看这些服务器日志。

环境变量
其次,让我们分开你的应用程序仍未运行的原因。当应用程序容器启动时,它会通过几个步骤来启动应用程序服务器。整个过程的入口点是/home/vmagent/python_vm_runtime/vmboot.py,它是容器中启动时运行的脚本。

问题是此脚本从多个环境变量中提取有关应用程序的信息。如果你做gcloud preview app run并以这种方式启动容器,你可以像这样启动一个shell:

$ gcloud preview app run <your_application.yaml>
$ boot2docker ssh
$ docker ps
<output omitted - use it to find your container id> 
$ docker exec -ti <your_container_id> /bin/sh
$ env
API_PORT=10000
HOSTNAME=b758e92cb8d6
HOME=/root
OLDPWD=/home/vmagent/python_vm_runtime/google/appengine/ext
GAE_MODULE_INSTANCE=0
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DEBIAN_FRONTEND=noninteractive
MODULE_YAML_PATH=app.yaml
GAE_PARTITION=dev
API_HOST=192.168.42.1
PWD=/home/vmagent/python_vm_runtime/google/appengine/ext/vmruntime
GAE_LONG_APP_ID=temp

事实证明,您特别错过了环境变量GAE_MODULE_INSTANCE=0。 vmconfig.py中有一行说:

instance = (os.environ.get('GAE_MODULE_INSTANCE') or
          _MetadataGetter('gae_backend_instance'))

在开发模式下,脚本需要处理环境变量,而不是_MetadataGetter。最终,应用程序容器将需要所有这些环境变量,否则它将继续在其他地方中断。

因此,当您执行docker run时,可以通过设置所有这些环境变量来运行应用程序。你可以用-e标志来做到这一点。您需要设置相当多的环境变量,因此我建议您编写一个shell脚本来执行此操作: - )