简体   繁体   中英

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?

eg 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. 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 ).

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

#!/bin/sh

sleep 10

[command to run MySQL]

echo "Started MySQL on xyz"

Then specify this script as ENTRYPOINT in your 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

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