为什么使用 Django+ docker-compose 跑就会一直卡在 Attaching to ?

dockerfile

FROM python:3.10-buster

RUN /usr/local/bin/python -m pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple

RUN mkdir /code

WORKDIR /code

COPY requirements-prd.txt /code/

RUN pip install -i https://mirrors.aliyun.com/pypi/simple -r requirements-prd.txt

COPY . /code/

ENV PYTHONDONTWRITEBYTECODE 1

ENV PYTHONBUFFERED 1

docker-compose.yaml

version: "3"

services:

twitter:

container_name: twitter

image: ponponon/twitter

ports:

- "8000:8000" # 这里的端口改为和 python manage.py runserver 0.0.0.0:8000 一样的端口才行

# command: python manage.py runserver 0.0.0.0:8000

command: ["python","manage.py", "runserver", "0.0.0.0:8000","--noreload"]

使用 docker run --rm -it ponponon/twitter python manage.py runserver 0.0.0.0:8080 一切正常

╰─➤  docker run --rm -it jiuzhang/twitter python manage.py runserver 0.0.0.0:8080

Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.

Run 'python manage.py migrate' to apply them.

April 27, 2023 - 03:55:27

Django version 3.1.3, using settings 'twitter.settings'

Starting development server at http://0.0.0.0:8080/

Quit the server with CONTROL-C.

但是使用 docker-compose 就有毛病, 永远卡在 Attaching to

╰─➤  docker-compose up  

[+] Running 2/2

⠿ Network twiter_default Created 0.0s

⠿ Container twitter Created 0.1s

Attaching to twitter

但是在另一个终端使用 docker ps -a 查看,是 running

╰─➤  docker ps -a                                                                                         130 ↵

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

e077317b374f jiuzhang/twitter "python manage.py ru…" 35 seconds ago Up 34 seconds 0.0.0.0:8000->8000/tcp twitter

但是使用 docker logs twitter 却是什么都没有

╰─➤  docker logs twitter

╭─ponponon@MBP13ARM ~/Desktop/code/me/free_workspace/twiter

╰─➤


回答:

使用关键字: "django docker-compose python manage.py runserver Attaching to" 去谷歌搜索,搜索到下面的词条:

https://stackoverflow.com/questions/50229873/unable-to-runserver-with-docker-compose-up

为什么使用 Django+ docker-compose 跑就会一直卡在 Attaching to ?

加上 tty: true 就行


然后,我发现

docker-compose up 的 tty 默认是false

docker run 的时候,如何加上了 -it, 那么 tty 是 true;没有没有加 -it,tty 就是 false

以上是 为什么使用 Django+ docker-compose 跑就会一直卡在 Attaching to ? 的全部内容, 来源链接: utcz.com/p/938857.html

回到顶部