使用Docker Run启动枪手实例码头图像

发布于 2025-01-26 12:19:32 字数 1476 浏览 3 评论 0原文

在我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄情伤 2025-02-02 12:19:33

You need to give gunicorn a module to actually run, e.g. app:main for an app.py file with a main function, and you should do this all as the CMD, not ENTRYPOINT, or from docker 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

み格子的夏天 2025-02-02 12:19:33

要解决此问题,我进行了以下操作:

  1. 删除了选项daemonenable_stdio_inheritance,以及preload从conf File。
  2. 我还将超时优雅的超时参数增加到120。Gunicorn
  3. 将寻找conf文件,并将使用其中定义的参数值,除非它们在cli中被覆盖。因此,我只是运行cmd [“ gunicorn”]

我认为最重要的更改是第1点,即守护程序到false(默认值),不确定为什么...我猜是作为守护程序过程,Docker容器不会正确地监视它,只是出口。

To solve this issue, I did the following:

  1. Removed the options daemon , enable_stdio_inheritance, and preload from the conf file.
  2. I also increased the timeout and graceful timeout parameters to 120.
  3. Gunicorn will look for a conf file, and will use the parameter values defined therein, unless they are overwritten in th CLI. Therefore, I just ran 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文