Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

312
Vistas
Display message success after docker-compose up is done

I run many services in my docker-compse.yml. I'd like to display a message to let user know when docker-compose up is done? I tried to echo message with command but my container exited with code 0

command: bash -c "echo Congratulation! You can use your containers now"

Is there anyway to let user know when docker-compose up is done? Many thanks!

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Anything you do in CMD will only be visible in the logs, and only per service, so you may as well just watch the logs which I assume is what you're trying to avoid. If you want it to work from the local command line you're going to need to wrap the docker-compose up command.

THE following is NOT fully tested. This is for guidance only. I use the getContainerHealth and waitContainer scripts myself, so can vouch for them. I'm fairly sure I found them on this site, but can't remember where.

Assuming you're waiting for your services to be in a usable state, you could use something similar to this compose file:

docker-compose.yml

services:
  serviceOne:
     // ... the usual stuff
    container_name: serviceOne
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 10s
      timeout: 10s
      retries: 3
      start_period: 1s

  serviceTwo:
     // ... the usual stuff
    container_name: serviceTwo
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 10s
      start_period: 1s

The commands in the test are the commands you use to define the service is up and running. More info here: https://docs.docker.com/compose/compose-file/#healthcheck

You will probably want different health checks (or at least intervals, timeouts, start_periods, etc) for production and development.

then some bash script that you use instead of docker-compose up:

getContainerHealth () {
  docker inspect --format "{{json .State.Health.Status }}" $1
}

waitContainer () {
  while STATUS=$(getContainerHealth $1); [ $STATUS != "\"healthy\"" ]; do
    if [ $STATUS = "\"unhealthy\"" ]; then
      echo "Failed!"
      exit -1
    fi
    printf .
    lf=$'\n'
    sleep 1
  done
  printf "$lf"
}

waitContainers () {
  waitContainer serviceOne
  waitContainer serviceTwo
  // ... for all services
}

docker-compose up
echo "In progress. Please wait"
waitContainers
echo "Done. Ready to roll."
over 4 years ago · Santiago Trujillo Denunciar

0

create a shell file echo.sh that contains echo "Your message"

In Docker file add CMD ["/dockerRepo/echo.sh"]

over 4 years ago · Santiago Trujillo Denunciar

0

Have you tried running something like the following directly in the Dockerfile itself ?

RUN echo -e "Your message"
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda