简体   繁体   English

docker-compose 不运行命令

[英]docker-compose not running commands

I have such docker-compose:我有这样的docker-compose:

web:
  build: ../../
  dockerfile: environments/production/Dockerfile
  links:
      - fpm:fpm
      - redis:redis
      - elasticsearch:elasticsearch
      - beanstalkd:beanstalkd
  volumes:
      - /var/cache/nginx
      - ../../:/app:ro
...
composer:
  image: imega/composer
  volumes:
    - ../../:/data
  command: ["install"]
node:
  image: node:slim
  volumes:
    - ../../:/app
  working_dir: /app
  entrypoint: npm
  command: ["install"]

The goal is to install composer and node deps on build.目标是在构建时安装 composer 和 node deps。 And it should work theoretically, but in fact command written in containers definition doesn't executing.理论上它应该可以工作,但实际上用容器定义编写的命令不会执行。 Any command.任何命令。 I've tried to run 'echo' there, or 'ls .'我试过在那里运行 'echo' 或 'ls 。 — nothing. - 没有。

Any ideas why?任何想法为什么?

I think you're misunderstanding a couple things here:我认为你在这里误解了几件事:

  • You are running npm install to install dependencies in a volume and then the volume is consumed by your application container.您正在运行npm install以在卷中安装依赖项,然后该卷由您的应用程序容器使用。 This isn't containing any dependencies in the application image.这不包含应用程序映像中的任何依赖项。 While this might work, it means that image doesn't really run on its own.虽然这可能有效,但这意味着该图像并不能真正独立运行。 When you ship this image to production, you are breaking a contract that says "this application is the same as development".当您将此映像交付到生产环境时,您违反了“此应用程序与开发相同”的合同。 Be aware of this.请注意这一点。
  • You are running npm install as a service which will eventually exit.您正在将npm install作为最终退出的服务运行。 When the command exits, the container stops.当命令退出时,容器停止。 More over, the web service (which likely depends on these dependencies) may start before the npm install has finished.此外, web服务(可能依赖于这些依赖项)可能会在npm install完成之前启动。

Is there a reason you don't want to have composer install and npm install as part of your application build process?您是否有理由不想将composer installnpm install作为应用程序构建过程的一部分?

don't use command: ["install"]不要使用命令:[“安装”]

to try:尝试:

command: install命令:安装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM