[英]Print status after docker-compose container starts
In a docker-compose file, is it possible to wait for a container to start and then print a status? 在docker-compose文件中,是否可以等待容器启动然后再打印状态?
eg sleep 10 && echo started mysql on http://${HOST}:${PORT}
例如
sleep 10 && echo started mysql on http://${HOST}:${PORT}
A Dockerfile
has a run command, but there isn't such a thing in a compose file. Dockerfile
有一个run命令,但是compose文件中没有这样的东西。 How can I do this? 我怎样才能做到这一点?
With docker-compose
, just like with a regular docker run [...]
, you can specify entrypoint
(cf. here ) and command
(cf. here ). 使用
docker-compose
,就像常规docker run [...]
,您可以指定entrypoint
(参见此处 )和command
(参见此处 )。
In your case, however, what I would do is building an own Docker image based on your preferred MySQL image and COPY
a simple entrypoint script into the image that does what you want, eg 但是,在您的情况下,我要做的是根据您喜欢的MySQL映像构建自己的Docker映像,然后将简单的入口点脚本
COPY
到执行所需功能的映像中,例如
#!/bin/sh
sleep 10
[command to run MySQL]
echo "Started MySQL on xyz"
Then specify this script as ENTRYPOINT
in your Dockerfile. 然后指定该脚本
ENTRYPOINT
在你的Dockerfile。
The best way is just add this to the compose file: 最好的方法是将其添加到撰写文件中:
print-status:
image: busybox
env_file: .env
command: "sh -c 'sleep 10 && echo \"http://localhost:${PORT}\"'"
depends_on:
- mysql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.