大网数据广告活动
服务器运维问答

Docker cannot access Webserver on host

· 52CE 我爱测

I'm trying to setup pythons django inside a dockerized environment Dockerfile FROM python:3.5-slim ENV PYTHONUNBUFFERED 1 RUN mkdir /code RUN pip install --upgrade pip WORKDIR /code ADD requirements.txt /code/ RUN pip install -r …

问题原文

原帖链接 · xhallix · CC BY-SA 3.0

I'm trying to setup pythons django inside a dockerized environment

Dockerfile

FROM python:3.5-slim
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
RUN pip install --upgrade pip
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
EXPOSE 8000

I build this to django-app.

docker-compose.yml

django:
  container_name: django
  image: django-app:latest
  ports:
    - "8000:8000"
  volumes:
    - ./config/startup.sh:/startup.sh
    - ./app:/code
  command: /bin/sh /startup.sh

startup.sh

#!/bin/sh
cd /code
django-admin.py startproject djagento
echo "Creating Project djagento"
cd djagento
python manage.py runserver

I am using ubuntu 14.04 LTS as my host system

docker exec -it django bash $curl 127.0.0.1:8000 is succesfull.

I am getting the ip of my container with docker inspect django

    "Gateway": "172.17.0.1",
    "IPAddress": "172.17.0.2"

But when trying to curl 172.17.0.1:8000 or curl 172.17.0.2:8000 or curl 127.0.0.1:8000 I am not able to get anything but connection reset

Edit

docker ps

baada462ae72        django-app:latest   "/bin/sh /startup.sh"   6 seconds ago       Up 5 seconds        0.0.0.0:8005->8000/tcp   django

*ON another Port, same result *

CONTAINER ID        IMAGE               COMMAND                 CREATED              STATUS              PORTS                    NAMES
a9d99ee563e5        django-app:latest   "/bin/sh /startup.sh"   About a minute ago   Up About a minute   0.0.0.0:8005->8000/tcp   django

Thanks

已采纳解答

原帖链接 · xhallix · CC BY-SA 3.0

For anyone stumbling upon this, you have to run the django server on 0.0.0.0:8000 inside the docker container, simply adding python django-admin runserver 0.0.0.0:8000 in my startup.sh fixed this for me

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。