使用Docker Run启动枪手实例码头图像
在我的Dockerfile中,对于烧瓶应用程序,我有一组按计划工作的命令。 我的Dockerfile的最后一行是:
ENTRYPOINT [ "/bin/bash", "-c" ]
我需要为此图像启动一些枪支实例。 因此,我在图像之外运行以下命令。
$ docker run -itd --name running_name -p 5000:5000 image_name bash
如果我没有bash奔跑,我将在几秒钟后自动输入容器...
$docker container exec -it running_name /bin/bash -c bash
现在,我启动了枪支实例,然后进行Docker Exit。由于执行,这些实例仍在运行。
有没有办法从Docker Run发射枪支实例,而无需进入容器?
我已经尝试了entrypoint [“ gunicorn”,“ - bind”,“ 0.0.0.0.0:5000”]
,但我仍然自动退出,
我也尝试将最后一行替换为cmd gunicorn - bind 0.0.0.0.0:5000
,然后做docker run -d -name run_name -p 5000:5000 image_name
我仍然会自动退出。
编辑:为了反映以下可能的答案,这是我的更新尝试和额外的信息。
以下文件都处于目录结构的相同级别。
在api_docker.py文件中,我有:
app = Flask(__name__)
api = Api(app)
api.add_resource(<some_code>)
在gunicorn.conf.py文件中,我有:
worker_class = "gevent"
workers = 2
timeout = 90
bind = "0.0.0.0:5000"
wsgi_app = "wsgi:app"
errorlog = "logging/error.log"
capture_output = True
loglevel = "debug"
daemon = True
enable_stdio_inheritance = True
preload = True
我也尝试从此文件中删除绑定和wsgi_app行。
在Dockerfile中:
<some_code>
CMD ["gunicorn", "--conf", "gunicorn.conf.py", "--bind", "0.0.0.0:5000", "api_docker:app"]
我成功地建造,然后我确实:
docker run -d --name name_run -p 5000:5000 name_image
In my dockerfile, for a Flask app, I have a set of commands that work as planned.
The last line of my dockerfile is currently:
ENTRYPOINT [ "/bin/bash", "-c" ]
I need to launch some gunicorn instances for this image.
So, I run the following commands in the terminal, outside the image.
$ docker run -itd --name running_name -p 5000:5000 image_name bash
If I run without bash, I'll just enter exit the container automatically after a few seconds...
$docker container exec -it running_name /bin/bash -c bash
Now that I'm in, I launch the gunicorn instances, and do docker exit. Because of exec, the instances are still running.
Is there a way to launch the gunicorn instances from docker run, without having to enter into the container?
I've tried ENTRYPOINT [ "gunicorn", "--bind", "0.0.0.0:5000" ]
but I still exit automatically
I've also tried substituting the last line for CMD gunicorn --bind 0.0.0.0:5000
and then do docker run -d --name run_name -p 5000:5000 image_name
I still exit automatically.
Edit: To reflect the possible answer below, here's my updated tries and extra information.
The following files are all at the same level of the directory structure.
In the api_docker.py file, I have:
app = Flask(__name__)
api = Api(app)
api.add_resource(<some_code>)
In the gunicorn.conf.py file, I have:
worker_class = "gevent"
workers = 2
timeout = 90
bind = "0.0.0.0:5000"
wsgi_app = "wsgi:app"
errorlog = "logging/error.log"
capture_output = True
loglevel = "debug"
daemon = True
enable_stdio_inheritance = True
preload = True
I've also tried removing the bind and wsgi_app rows, from this file.
In the dockerfile:
<some_code>
CMD ["gunicorn", "--conf", "gunicorn.conf.py", "--bind", "0.0.0.0:5000", "api_docker:app"]
I build successfully, and then I do:
docker run -d --name name_run -p 5000:5000 name_image
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要给出
gunicorn
一个实际运行的模块,例如用于app.py
带有main
函数的文件,您应该以cmd
而不是来执行所有操作entrypoint
,或从docker运行
中,除非您计划在实际运行图像时提供进一步的与Gunicorn相关的参数。 (运行参数或CMD附加到入口处)或者,您可以使用已经为您提供这些详细信息的现有映像 - 例如docker“ rel =” nofollow noreferrer> https://github.com/tiangolo/meinheld-gunicorn-flask-docker
You need to give
gunicorn
a module to actually run, e.g.app:main
for anapp.py
file with amain
function, and you should do this all as theCMD
, notENTRYPOINT
, or fromdocker run
unless you plan on providing further gunicorn-related arguments when you actually run the image. (run arguments or the CMD are appended to the ENTRYPOINT)Or, you could use an existing image that already has these details for you - e.g. https://github.com/tiangolo/meinheld-gunicorn-flask-docker
要解决此问题,我进行了以下操作:
daemon
,enable_stdio_inheritance
,以及preload
从conf File。超时
和优雅的超时
参数增加到120。Gunicorncmd [“ gunicorn”]
。我认为最重要的更改是第1点,即守护程序到false(默认值),不确定为什么...我猜是作为守护程序过程,Docker容器不会正确地监视它,只是出口。
To solve this issue, I did the following:
daemon
,enable_stdio_inheritance
, andpreload
from the conf file.timeout
andgraceful timeout
parameters to 120.CMD ["gunicorn"]
.I think the most important change was that of point 1, namely the daemon to false(which is the default), not sure why though... I would guess that as a daemon process, the docker container would not monitor it correctly and just exit.