簡體   English   中英

dockerizing django, docker-compose 工作,但 docker 運行

[英]dockerizing django, docker-compose works but not docker run

我在這里[https://github.com/MrAmbiG/shorty/tree/k8s][1]有一個 django 應用程序(k8s 的網址縮短器)。 docker-compose版本適用於相同的 docker 映像,但docker run不起作用(我無法從主機訪問,沒有錯誤)。 Docker and docker-compose up both are from docker.io and both are using the same docker image but why the difference? 我很抱歉沒有發布文件的所有內容,而是發布 github url 本身。

version: '3.7'

services:
  django:
    image: gajuambi/shorty
    ports:
      - 80:8001
    env_file:
      - ../.env

下面不起作用
docker run --name shorty -it --env-file.env gajuambi/shorty -p 8001:8001 The docker image itself runs with no error but when I enter the address in the browser of the host (my windows laptop) and I一無所獲。 我在運行 docker 的主機中嘗試了以下網址(筆記本電腦)瀏覽器
http://localhost:8001/
http://127.0.0.1:8001/
我嘗試將 django 綁定到以下地址
0.0.0.0
0
127.0.0.1
但沒有 go。

端口:- 80:8001

我認為您的應用程序在端口80上運行,因為您嘗試在0.0.0.0默認端口上綁定應用程序將是 80

但是您在運行 docker 命令時轉發端口8001

請嘗試

docker run --name shorty -it --env-file .env  gajuambi/shorty -p 8001:80

另外,嘗試打開主機(計算機)的IP**docker bridge IP**

http://{主機IP}:8001

將入口點命令更新為daphne shorty.asgi:application -b 0 -p 8000
目前docker rm shorty -f && docker build -t gajuambi/shorty -f.\Deployment\Dockerfile. && docker run --name shorty -it --env-file.env -p 80:8000 gajuambi/shorty docker rm shorty -f && docker build -t gajuambi/shorty -f.\Deployment\Dockerfile. && docker run --name shorty -it --env-file.env -p 80:8000 gajuambi/shorty工作正常。 我已更新 github 存儲庫以供參考。 https://github.com/MrAmbiG/shorty.git

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM