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

356
Visualizações
Docker Continue to Run process in background even after kill

I am using docker to run a python script that uses subprocess module to run some commands in terminal ,

After Running the script using docker, if i use ctrl+c or kill command to kill the the process , in my terminal process is getting killed, but process continue to run in background and create logs as well.

I tried running the script directly in my system , and it works fine and after killing it just stop, but when i ran using docker it continue to run in background even after kill -9 process_id.

sample code to simulate the issue.

import getpass
import subprocess
import os
import signal, time

print('python user: ', getpass.getuser())

def test(i):
    try:
        drop_temp_tbl = subprocess.Popen(f'echo "test">>test.txt;sleep 40; echo "test6{i}">>test.txt;',
                                         shell=True,
                                         stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        (drop_temp_tbl_stdout, drop_temp_tbl_stderr) = drop_temp_tbl.communicate()
        print('_subprocess_user,', drop_temp_tbl_stdout, '\n', drop_temp_tbl_stderr)
    except Exception as e:
        print('terminate ',os.killpg(os.getpgid(drop_temp_tbl.pid), signal.SIGTERM) )
        print('ERROR', e)


for i in range(2):
    test(i)

Docker run command

docker run -i --rm -v `pwd`:/code ${docker_id} python_script.py

Dockerfile

FROM ubuntu:latest


RUN apt-get update && \
  apt-get install -yf software-properties-common

RUN  apt-get -yq update && \
     apt-get -yqq install \
     openssh-client

COPY ./docker_requirement ./
RUN pip install --no-cache-dir -r docker_requirement

RUN groupadd --gid 1000 app
RUN useradd --uid 1000 --gid app --home /app app

USER 1000
ADD . /code
WORKDIR /code
ENTRYPOINT ["python3"]

for above example running through docker will continue to append test.txt even after kill -9 process_id

over 4 years ago · Santiago Trujillo
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