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

213
Visualizações
Using custom shell script as docker entrypoint

I’m trying to use docker-compose to bring up a container. As an ENTRYPOINT, that container has a simple bash script that I wrote. Now, when I try to bring up the container in any of the below ways:

  • docker-compose up
  • docker-compose up foo

it doesn’t complete. i.e., trying to attach (docker exec -i -t $1 /bin/bash) to the running container, fails with:

Error response from daemon: Container xyz is restarting, wait until the container is running.

I tried playing around with putting commands in the background. That didn’t work.

my-script.sh

cmd1 &
cmd2 &&
...
cmdn &

I also tried i) with and without entrypoint: /bin/sh /usr/local/bin/my-script.sh and ii) with and without the tty: true option. No dice.

docker-compose.yml

version: '2'
services:
  foo:
    build:
      context: .
      dockerfile: Dockerfile.foo
    ...
    tty: true
    entrypoint: /bin/sh /usr/local/bin/my-script.sh

Also tried just a manual docker build / run cycle. And (without launching /bin/sh in the ENTRYPOINT ) the run just exits.

$ docker build ... .
$ docker run -it ... 
... shell echos commands here, then exits
$

I'm sure its something simple. What's the solution here?

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

0

Your entrypoint in your docker-compose.yml only needs to be

entrypoint: /usr/local/bin/my-script.sh

Just add #! /bin/sh to the top of the script to specify the shell you want to use.

You also need to add exec "$@" to the bottom of your entrypoint script or else it will exit immediately, which will terminate the container.

about 4 years ago · Santiago Trujillo Relatório

0

First of all you need to put something infinite to keep running your container in background,like you can tail -f application.log or anything like this so that even if you exit from your container bash it keeps running in background

you do not need to do cmd1 & cmd2 &&...cmdn & just place one command like this touch 1.txt && tail -f 1.txt as a last step in your my-script.sh. It will keep running your container. One thing also you need to change is docker run -it -d -d will start container with background mode.If you want to go inside your container than docker exec -it container_name/id bash debug the issue and exit.It will still keep your container running until you stop with docker stop container_id/name Hope this help. Thank you!

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