Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

305
Visualizações
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!

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

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."
about 4 years ago · Santiago Trujillo Relatório

0

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

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

about 4 years ago · Santiago Trujillo Relatório

0

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

RUN echo -e "Your message"
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda