docker container已构建并正在运行但无法正常工作

时间:2018-05-03 03:29:59

标签: django docker docker-compose dockerfile

我的名字是奥马尔。我有一个docker图像和容器,用于我刚刚创建并运行的项目。所以我目前正在尝试在我的本地机器上测试它,然后将其推送到在线环境。我构建它没有以前的缓存,它构建了一个在线运行的新docker。为什么它在我的浏览器中不起作用。这就是我所拥有的。

(MySplit) omars-mbp:mysplit omarjandali$ docker build --no-cache -t validation_test_1 .
Sending build context to Docker daemon  56.07MB
Step 1/7 : FROM python:3
 ---> 79e1dc9af1c1
Step 2/7 : WORKDIR users/
Removing intermediate container 7030351beb91
 ---> 30ac3f4ccbae
Step 3/7 : COPY requirements.txt ./
 ---> 57cbbd7335ab
Step 4/7 : EXPOSE 80
 ---> Running in 592407a176ff
Removing intermediate container 592407a176ff
 ---> 523945ea529f
Step 5/7 : RUN pip install -r requirements.txt
 ---> Running in 48347f772fbe
Collecting Django==1.11.5 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/18/2d/b477232dd619d81766064cd07ba5b35e956ff8a8c5c5d41754e0392b96e3/Django-1.11.5-py2.py3-none-any.whl (6.9MB)
Collecting gunicorn==19.7 (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/96/4b/bc4bc2dad60defaa3f7d8590dc51331a225a5399380c161047c1224cd86d/gunicorn-19.7.0-py2.py3-none-any.whl (112kB)
Collecting django-localflavor==1.5.3 (from -r requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/da/47/69e53f69fb50a38766aa929c1f81fd2e6315edc7f3945174ead24ffcf6df/django-localflavor-1.5.3.tar.gz (4.7MB)
Collecting synapse_pay_rest_native==3.1.1 (from -r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/43/27/b73d83dd50d4dfec1680d22896b800ddbb6bf8fb3f3a1755a916a6e4f732/synapse_pay_rest_native-3.1.1.tar.gz
Collecting pytz (from Django==1.11.5->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/dc/83/15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2/pytz-2018.4-py2.py3-none-any.whl (510kB)
Collecting requests (from synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl (88kB)
Collecting chardet<3.1.0,>=3.0.2 (from requests->synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
Collecting idna<2.7,>=2.5 (from requests->synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl (56kB)
Collecting urllib3<1.23,>=1.21.1 (from requests->synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/63/cb/6965947c13a94236f6d4b8223e21beb4d576dc72e8130bd7880f600839b8/urllib3-1.22-py2.py3-none-any.whl (132kB)
Collecting certifi>=2017.4.17 (from requests->synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl (150kB)
Building wheels for collected packages: django-localflavor, synapse-pay-rest-native
  Running setup.py bdist_wheel for django-localflavor: started
  Running setup.py bdist_wheel for django-localflavor: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/36/41/a8/30c023fe29300f1a19d0520aaff1faf9e4c7ab176c53913ab5
  Running setup.py bdist_wheel for synapse-pay-rest-native: started
  Running setup.py bdist_wheel for synapse-pay-rest-native: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/33/93/7f/6bd8dd39a1c22e2ef85a259a45e603dff2b0ab4d6209a7a976
Successfully built django-localflavor synapse-pay-rest-native
Installing collected packages: pytz, Django, gunicorn, django-localflavor, chardet, idna, urllib3, certifi, requests, synapse-pay-rest-native
Successfully installed Django-1.11.5 certifi-2018.4.16 chardet-3.0.4 django-localflavor-1.5.3 gunicorn-19.7.0 idna-2.6 pytz-2018.4 requests-2.18.4 synapse-pay-rest-native-3.1.1 urllib3-1.22
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Removing intermediate container 48347f772fbe
 ---> 5749b63a2fef
Step 6/7 : COPY . .
 ---> 7754d9db1f38
Step 7/7 : CMD ["python", "manage.py", "runserver"]
 ---> Running in 362648ae0426
Removing intermediate container 362648ae0426
 ---> c26bf2de11b4
Successfully built c26bf2de11b4
Successfully tagged validation_test_1:latest
(MySplit) omars-mbp:mysplit omarjandali$ docker run -d -P validation_test_1:latest
b038c688ba4e681c03d8e093cf630a564d2f7cea27812b55dd0d1c33aa0f27b4
(MySplit) omars-mbp:mysplit omarjandali$ docker ps
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                   NAMES
b038c688ba4e        validation_test_1:latest   "python manage.py ru…"   5 seconds ago       Up 4 seconds        0.0.0.0:32768->80/tcp   zealous_mcnulty
(MySplit) omars-mbp:mysplit omarjandali$

我尝试了以下localhost:32768127.0.0.1:32768有没有人知道为什么会发生这种情况。

我已经允许我的django项目中的所有主机。

dockerfile

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

1 个答案:

答案 0 :(得分:2)

这是因为Django的runserver仅默认接受来自127.0.0.1的连接,当您从浏览器点击localhost:32768时,连接不会来自127.0.0.1 / { {1}},但来自您的实际主机IP。

将您的localhost更改为:

CMD