gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:20:37 26 4
gpt4 key购买 nike

我有以下 docker 文件:

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'

但现在我得到以下错误:

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

我可以做什么样的配置或操作,以便我可以在 docker 内部运行这个 docker 镜像,例如:

sudo docker run gcr.io/MY-PROJECT/ae-image

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

最佳答案

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

卷绑定(bind)
首先,让我们看一下日志目录部分,您在其中创建/var/log/appengine。当 gcloud preview app run 作用于容器时,它实际上使用卷绑定(bind)运行它,将容器内的/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 脚本来完成它:-)

关于python - 如何在计算引擎实例上运行 google appengine docker 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30646410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com