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

820
Visualizações
Restart Docker container on inner process crash

Update: Found secret cause - nodemon

The answer is just to set the container to restart on crash. In development, I'm using nodemon which prevents the process from exiting on a crash - so I assumed that the process crashing didn't cause the container to exit. My mistake. The process crashing does in fact cause the container to exit when using node and not nodemon.

{
  "scripts": {
    "development:service": "nodemon ./service/server.js",
    "production:service": "node ./service/server.js"
  }
}

Original Question

How do I restart a docker container when a process inside the container crashes?

Would the best way be to set --autorestart ON_FAILURE for the container and then make the container crash when the inner process crashes? If so, how do I force the container to crash when one of it's process crashes?

I'm using the image node:10.15.3.

Useful Link: how to make a container restart if the container, itself, crashes

Dockerfile

FROM node:10.15.3 

ENV NODE_ENV development

# Create application directory.
RUN mkdir -p /src
WORKDIR /src

# Install app dependencies and build.
ADD . /src
RUN yarn install --force

RUN ["chmod", "+x", "./run.sh"]
CMD [ "./run.sh" ]

Processes (simplified)

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
user        13  0.0  0.1  17952  2840 ?        S    15:09   0:00 bash ./install.sh
user        72  0.5  3.2 889668 66728 ?        Sl   15:09   0:00 /usr/local/bin/node /opt/yarn-v1.13.0/bin/yarn.js start 
user        97  2.4  3.2 919992 65748 ?        Sl   15:09   0:01 /usr/local/bin/node ./service/server.js
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can use the --restart flag for docker run command https://docs.docker.com/engine/reference/commandline/run/#restart-policies---restart

Example: docker run --restart=on-failure my-image-name

Or if you are using docker-compose then you restart: on-failure for the service https://docs.docker.com/compose/compose-file/#restart

over 4 years ago · Santiago Trujillo Relatório

0

When you run multiple services in a container, and you are very, very sure you want this (it's best practice to run a single process in a single container), you may want a process supervisor (for example systemd) which restart any crashed process inside, or crash if any of it's supervised processes crash.

There are also some other, more lightweight, ways to accomplish this, like a wrapper bash script.

It's all described here: https://docs.docker.com/config/containers/multi-service_container/

Edit after question was updated with Dockerfile:

The easiest way is probably to make sure run.sh crashes if any of it's subprocesses crash. Then the container will crash, and optionally restart if you use --restart=on-failure in docker run.

over 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