我想在运行完脚本后立即运行脚本
`docker-compose up -d` 这是我的docker-compose.yml代码片段。其他设置为mysql server、redis...etc....but,它们不会造成任何问题
web:
image: nginx
container_name: web-project
volumes:
- ./code:/srv
working_dir: /srv/myweb
extra_hosts:
- "myweb.local:127.0.0.1"
ports:
- 8081:80
# tty: true
command: sh /srv/scripts/post-run-web.sh因此,每当我运行docker-compose up -d或docker-compose up时,它都会停止。(容器不会一直运行)。尽管我的shell脚本很简单(运行echos...or phpunit)。这是我的脚本。
#!/bin/bash
echo running post install scripts for web..;
cd /srv/myweb
npm install
composer self-update
composer update这就是我得到的错误。这就像服务器(nginx)还没有运行一样。另外,如果我使用exec bash连接到服务器,并检查进程。我还没有看到nginx运行。
web_1 | You are already using composer version 7a9eb02190d334513e99a479510f87eed18cf958.
web_1 | Loading composer repositories with package information
web_1 | Updating dependencies (including require-dev)
web_1 | Generating autoload files
web-project exited with code 0
Gracefully stopping... (press Ctrl+C again to force)
Stopping mysql-project... done
Stopping rabbitmq-project... done
Stopping redis-project... done那么,尽管该脚本在语法上是正确的,但它为什么要退出呢?我怎样才能让它正确运行?(我在做什么,设置错误!)
发布于 2015-10-08 16:03:57
command将覆盖默认命令。
这就是容器停止的原因: nginx永远不会启动。
在脚本结束时,您必须运行nginx
#!/bin/bash
echo running post install scripts for web..;
cd /srv/myweb
npm install
composer self-update
composer update
nginx顺便说一下,我建议您仅在需要时更改脚本并运行npm install和composer *update (因此,仅当/src/myweb中的某些文件不存在时),因为这会徒劳地增加容器的启动时间。
请注意,通过这样做,NginX将永远不会捕获由docker stop发送的SIGTERM信号。这可能会导致它突然被杀死。
相反,如果您希望确保nginx接收到SIGTERM,则必须将最后一行替换为exec nginx。这用nginx本身替换了bash进程。
https://stackoverflow.com/questions/33009825
复制相似问题