Home > database >  Docker can't run the file
Docker can't run the file

Time:06-26

When I prescribe docker-compose up, the following error comes out, which I don't quite understand how to fix!

ERROR: for a1e9335fc0e8_bot Cannot start service tgbot: failed to create shim: OCI runtime create failed: runc create failed: unable to start container process: exec: "python3 main.py": executable file not found in $PATH: unknown

My Dockerfile:

FROM python:latest

WORKDIR /src
COPY req.txt /src
RUN pip install -r req.txt
COPY . /src 

My docker-compose.yml:

version: "3.1"

services:
  db:
    container_name: database
    image: sameersbn/postgresql:10-2
    environment:
      PG_PASSWORD: $PGPASSWORD
    restart: always
    ports:
      - 5432:5432
    networks:
      - botnet
    volumes:
      - ./pgdata:/var/lib/postgresql

  tgbot:
      container_name: bot
      build:
        context: .
      command:
        - python3 main.py
      restart: always
      networks:
        - botnet
      env_file:
        - ".env"
      depends_on:
        - db


networks:
  botnet:
    driver: bridge

CodePudding user response:

Your command: is in the array format, so compose thinks that the executable file is called python3 main.py. That doesn't exist.

Change it to this and it'll work

tgbot:
  container_name: bot
  build:
    context: .
  command: python3 main.py
  restart: always
  networks:
    - botnet
  env_file:
    - ".env"
  depends_on:
    - db

More info here.

  • Related