【问题标题】:Conflicting / Multiple start commands between `Dockerfile` and `docker-compose.yml``Dockerfile` 和 `docker-compose.yml` 之间的冲突/多个启动命令
【发布时间】:2019-09-20 23:21:42
【问题描述】:

我在关注 this tutorial 以在 Docker 上启动并运行 Rails 6 应用程序(尽管这个问题并非特定于 Rails)

Dockerfile 中有如下命令

# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

太好了,所以它给了它一个启动命令来在本地启动 rails 服务器。

稍后在同一篇文章中,它在docker-compose.yml 文件中显示以下内容:

services:
  ...

  web:
    build: .
    command: bash -c "foreman start -f Procfile.dev-server"
    ...

现在它提供了一个不同的命令来启动应用程序(使用foreman gem,它可能以与第一个命令类似的方式启动rails服务器)。

哪个“命令”是真正执行并启动一切的命令?当我运行docker-compose up 时,docker-compose 命令会覆盖Dockerfile CMD 吗?

【问题讨论】:

    标签: docker docker-compose


    【解决方案1】:

    docker-compose.yml 中的command:docker run 命令末尾给出的命令优先。不管你指定什么,容器只运行一个命令,然后退出。

    在打包单个应用程序的典型映像中,最佳实践是将应用程序代码(或编译后的二进制文件)COPY 并设置一个适当的CMD 来运行它,即使在开发中你将运行它修改后的设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      相关资源
      最近更新 更多