'python: can't open file 'manage.py': [Errno 2] No such file or directory when compose docker

I run two different Apps in containers.

  1. Django App
  2. Flask App

Django ran just well. I configured my Flask App as follow:

This Is a docker-compose.yml

version: '3.8'
services:
  backend:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8001:5000
    volumes:
      - .:/app
    depends_on:
      - db

  db:
    image: mysql:5.7.22
    restart: always
    environment:
      MYSQL_DATABASE: main
      MYSQL_USER: username
      MYSQL_PASSWORD: pwd
      MYSQL_ROOT_PASSWORD: pwd
    volumes:
      - .dbdata:/var/lib/mysql
    ports:
      - 33067:3306

This also is my Dockerfile

FROM python:3.8
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app

CMD python main.py

Problem: When I run docker-compose up the following error occurs

backend_1  | python: can't open file 'manage.py': [Errno 2] No such file or directory

I don't know why it tries to open manage.py file since it is Flask and not Django App. I need your help. Thanks in Advance.



Solution 1:[1]

I started a new Flask app(but this time on virtualenv) and my problem fixed :)

Solution 2:[2]

I'm not sure how this will work for you but, I resolved this by changing my docker-compose.yml to have a command parameter, so it looks like this

version: '3.8'
services:
  backend:
    build:
      context: .
      dockerfile: Dockerfile
    command: 'python main.py' << Updated Line >>
    ports:
      - 8001:5000
    volumes:
      - .:/app
    depends_on:
      - db

  db:
    image: mysql:5.7.22
    restart: always
    environment:
      MYSQL_DATABASE: main
      MYSQL_USER: username
      MYSQL_PASSWORD: pwd
      MYSQL_ROOT_PASSWORD: pwd
    volumes:
      - .dbdata:/var/lib/mysql
    ports:
      - 33067:3306

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Alkari