[英]Docker compose executable file not found in $PATH": unknown
but I'm having a problem.但我遇到了问题。
Dockerfile: 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 : 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.起初,我认为 Python Manage 是错误的。
But i tried command ls
, To my surprise, I succeeded.但是我尝试了命令
ls
,令我惊讶的是,我成功了。
Then I tried the ls -al command, but it failed.然后我尝试了 ls -al 命令,但它失败了。
I think the addition of a command to write space is causing a problem.我认为添加写入空间的命令会导致问题。
how can i fix it ?我该如何解决?
When you use list syntax in the docker-compose.yml
file, each item is taken as a word.当您在
docker-compose.yml
文件中使用列表语法时,每一项都被视为一个词。 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或者让 Docker Compose 为你做
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
.一般来说,像这样的图像的固定属性应该在 Dockerfile 中指定,而不是在
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.使用图像中内置的代码和其中定义的合理默认命令,您可以从
docker-compose.yml
文件中删除volumes:
和command:
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.