简体   繁体   中英

docker-compose not running commands

I have such 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. 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 .' — 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. 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. 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.

Is there a reason you don't want to have composer install and npm install as part of your application build process?

don't use command: ["install"]

to try:

command: install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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