我的問題是當我在容器上運行我的應用程式并映射一個埠時,該應用程式沒有在我的本地機器上運行。
我使用 ubuntu,這是我的 dockerfile:
FROM python:3.8.13-alpine3.14
WORKDIR /app/
COPY ./requirements.txt .
RUN apk add -u zlib-dev jpeg-dev gcc musl-dev
RUN python3 -m pip install --upgrade pip
RUN pip3 install -r requirements.txt
COPY . .
ENV API_URL='http://my_api.com'
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "8000"]
當我使用下面的命令運行影像時,django app 在容器中啟動。
docker run -d -p 8000:8000 dj-test
我這么說是因為當我在這個容器中運行 shell 時
docker exec -it e906801932ac sh
我檢查了一下127.0.0.1:8000,這是回復:
/app # wget localhost:8000
Connecting to localhost:8000 (127.0.0.1:8000)
saving to 'index.html'
index.html 100% |*****************************************************************************************************************************| 10697 0:00:00 ETA
'index.html' saved
但是當我在本地機器上嘗試這個時,回應是不同的。
wget localhost:8000
--2022-04-23 18:48:06-- http://localhost:8000/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2022-04-23 18:48:07-- (try: 2) http://localhost:8000/
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2022-04-23 18:48:09-- (try: 3) http://localhost:8000/
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2022-04-23 18:48:12-- (try: 4) http://localhost:8000/
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2022-04-23 18:48:16-- (try: 5) http://localhost:8000/
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
當我在這里嘗試docker ps是回應:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e906801932ac dj-test "python manage.py ru…" 29 minutes ago Up 29 minutes 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp nice_goldwasser
你能幫我在這里找到問題嗎?謝謝。
uj5u.com熱心網友回復:
您需要在 CMD 命令中進行"8000"替換 。"0.0.0.0:8000"
看更多:
django 更改默認運行服務器埠
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/462649.html
標籤:码头工人
上一篇:如何穩健地決議PostgreSQL錢(在Python中)
下一篇:JS中的影像更改功能問題
