docker图像正在运行,但网页错误 - Docker

时间:2017-11-14 23:18:12

标签: django docker docker-machine

我有一个基本的django项目,我试图让它通过docker在本地运行。我有docker文件。我构建了docker镜像。我跑了码头图像。它正在运行,但是我的网页在屏幕上显示错误,因为它没有连接到docker服务器......这就是我所拥有的:

docker file:

FROM python:3
WORKDIR general
COPY requirements.txt ./
EXPOSE 8000
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

以下是我如何建立和运行这个项目:

omars-mbp:split omarjandali$ docker build -t splitbeta/testing2 .
Sending build context to Docker daemon  223.7kB
Step 1/7 : FROM python:3
 ---> 79e1dc9af1c1
Step 2/7 : WORKDIR general
 ---> 04a6f8a7f92a
Removing intermediate container b2ffb485e485
Step 3/7 : COPY requirements.txt ./
 ---> 649d77ec499e
Step 4/7 : EXPOSE 8000
 ---> Running in 7d8d6fe8de1d
 ---> c328d885a5f1
Removing intermediate container 7d8d6fe8de1d
Step 5/7 : RUN pip install -r requirements.txt
 ---> Running in 1c9aca43dc14
Collecting Django==1.11.5 (from -r requirements.txt (line 1))
  Downloading Django-1.11.5-py2.py3-none-any.whl (6.9MB)
Collecting gunicorn==19.6.0 (from -r requirements.txt (line 2))
  Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
Collecting pytz (from Django==1.11.5->-r requirements.txt (line 1))
  Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
Installing collected packages: pytz, Django, gunicorn
Successfully installed Django-1.11.5 gunicorn-19.6.0 pytz-2017.3
 ---> 602e88557c8b
Removing intermediate container 1c9aca43dc14
Step 6/7 : COPY . .
 ---> 55cff629cb51
Step 7/7 : CMD python manage.py runserver 0.0.0.0:8000
 ---> Running in efd75f8fb602
 ---> 2cef664a626d
Removing intermediate container efd75f8fb602
Successfully built 2cef664a626d
Successfully tagged splitbeta/testing2:latest
omars-mbp:split omarjandali$ docker run -d spltibeta/testing2

这是项目运行:

omars-mbp:split omarjandali$ docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS               NAMES
fc14f03a18b0        splitbeta/testing2   "python manage.py ..."   3 seconds ago       Up 3 seconds        8000/tcp            loving_volhard

当网页显示模板页面时,网页出现以下错误....

This site can’t be reached

127.0.0.1 refused to connect.

我昨天跑了,但它不再工作......我不知道为什么。我没有改变任何东西

我已登录终端

中的dockerhub帐户

1 个答案:

答案 0 :(得分:1)

看来您的Docker运行命令不会发布端口8000.默认情况下,如果您没有明确告诉它,则docker不会在主机系统上发布任何容器端口。尝试使用-p or --publish option of docker run

docker run -d -p 8000:8000 spltibeta/testing2

或者,您可以使用-P或--publish-all选项在主机系统上发布容器的所有公开端口。这将在主机上分配一个随机端口。

docker run -d -P spltibeta/testing2