Python running flask in host as part of "docker compose up" command

Hello,
I am new to docker. I am trying to run a yml file and its working as expected. However I can see a python process running flask. When I bring down the docker the host python also stops. Is this normal behaviour ? Here is yml file

Note : I am using “docker compose up build” nor “docker-compose”

version: '3.8'

services:
  bc365mw_v2:
    build: .
    ports:
      - "50001:5000"
    volumes:
      - .:/app
    command: flask run --host=0.0.0.0
    depends_on:
      - mysql

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: <pwd>
      MYSQL_DATABASE: caredb
    ports:
      - "3306:3306"
    volumes:
      - mysql-data:/var/lib/mysql

volumes:
  mysql-data:

and Dockerfile for build app is as follows

# Use an official Python runtime as a parent image
FROM python:3.11-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Make port 5000 available to the world outside this container
EXPOSE 5000

# Define environment variable for Flask
ENV FLASK_APP=app.py

# Run app.py when the container launches
CMD ["flask", "run", "--host=0.0.0.0"]

Thanks in advance. Pls pardon if it is a basic qz. I am just starting on docker.
Prem

Can you elaborate on this? Why woulds stopping a container stop a python process on the host?

Pls see the attached screenshot for the sequence of commands. when ever docker is running i can see the following process running in the host

root     1894953 11.0  0.4  76788 65896 ?        Ss   17:22   0:00 /usr/local/bin/python3.11 /usr/local/bin/flask run --host=0.0.0.0

Please use ps auxf without grep, and you will see that your flask command is a child process of /usr/bin/containerd-shim-runc-v2. Of course a child process will terminate, if the parent process is terminated by removing the container.

1 Like