When running a python shell directly from a docker-compose run
, the parent PID shows up as 0, which feels very wrong. I've put together a very simple, reproducible case below:
# Dockerfile
FROM python:3.7-buster
COPY . /code/
WORKDIR /code
# docker-compose.yml
version: '3'
services:
thing:
build: .
volumes:
- .:/code
When I run a python shell from within this, its ppid is 0; likewise to any python code running this way (if running tests with pytest
for example):
$ docker-compose run thing python
>>> import os
>>> os.getpid()
1
>>> os.getppid()
0
When I run a python shell from within a bash shell, I see a more sane value...
$ docker-compose run thing bash
root@<id> # python
>>> import os
>>> os.getpid()
6
>>> os.getppid()
1
When I run the python shell straight on my host machine, I also see more sane PID values...
$ python
>>> import os
>>> os.getpid()
25552
>>> os.getppid()
1133
I'm sure this is some strange behavior on how docker
treats processes in a running container, but it doesn't seem to me like a PID should ever be 0. Is this expected behavior, and if so is there a workaround for Python code running this way that relies on a parent PID?