Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose executable file not found in $PATH": unknown

but I'm having a problem.

Dockerfile:

FROM python:3
ENV PYTHONUNBUFFERED 0
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

compose.yml :

version: '3'

services:
  db:
    image: postgres
    volumes:
      - ./docker/data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=sampledb
      - POSTGRES_USER=sampleuser
      - POSTGRES_PASSWORD=samplesecret
      - POSTGRES_INITDB_ARGS=--encoding=UTF-8

  django:
    build: .
    environment:
      - DJANGO_DEBUG=True
      - DJANGO_DB_HOST=db
      - DJANGO_DB_PORT=5432
      - DJANGO_DB_NAME=sampledb
      - DJANGO_DB_USERNAME=sampleuser
      - DJANGO_DB_PASSWORD=samplesecret
      - DJANGO_SECRET_KEY=dev_secret_key
    ports:
      - "8000:8000"
    command:
      - python3 manage.py runserver
    volumes:
      - .:/code

error :

ERROR: for django  Cannot start service django: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"python3 manage.py runserver\": executable file not found in $PATH": unknown

At first, I thought Python Manage was wrong.

But i tried command ls , To my surprise, I succeeded.

Then I tried the ls -al command, but it failed.

I think the addition of a command to write space is causing a problem.

how can i fix it ?

like image 968
killer whale Avatar asked Dec 06 '19 09:12

killer whale


People also ask

How to fix Docker can not execute the shell script?

If you look at the above error then you can see docker can not execute the shell script(my-custom-script.sh) How to fix it? Make sure the script my-custom-script.sh is available - the First check which you should perform is by checking the shell script my-custom-script.sh if it's available or not.

How to use list syntax in Docker-Compose?

When you use list syntax in the docker-compose.yml file, each item is taken as a word. You're running the shell equivalent of In general fixed properties of the image like this should be specified in the Dockerfile, not in the docker-compose.yml.

What does exec Python mean in Docker?

Generally, we tend to focus on the remaining part of the error but if you look carefully in the above error then it stats the exec: "python" which mean the docker entrypoint_ is not able to run or execute the python program_. How to fix it?

Why is docker-compose so verbose?

Now Docker ain't a shell and therefore the message is a bit more verbose (and that docker-compose is running docker is also adding in front of it):


1 Answers

When you use list syntax in the docker-compose.yml file, each item is taken as a word. You're running the shell equivalent of

'python3 manage.py runserver'

You can either break this up into separate words yourself

command:
  - python3
  - manage.py
  - runserver

or have Docker Compose do it for you

command: python3 manage.py runserver

In general fixed properties of the image like this should be specified in the Dockerfile, not in the docker-compose.yml. Every time you run this image you're going to want to run this same command, and you're going to want to run the code built into the image. There are two syntaxes, with the same basic difference:

# Explicitly write out the words
CMD ["python3", "manage.py", "runserver"]

# Docker wraps in sh -c '...' which splits words for you
CMD python3 manage.py runserver

With the code built into the image and a reasonable default command defined there, you can delete the volumes: and command: from your docker-compose.yml file.

like image 168
David Maze Avatar answered Oct 11 '22 06:10

David Maze