无法通过本地主机访问我在Docker上的Web服务器

时间:2018-07-13 16:08:36

标签: django docker nginx

我正在按照本教程来实现dockerized django应用程序:

http://ruddra.com/2016/08/14/docker-django-nginx-postgres/

我能够毫无问题地构建和运行docker镜像和conatiner。

例如,我从容器获得的服务处于以下状态:

docker ps

enter image description here

docker-compose logs web

enter image description here

docker-compose logs nginx不会改变

Dockerfile是:

FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /config
ADD /config/requirements.pip /config/
RUN pip install -r /config/requirements.pip
RUN mkdir /src;
WORKDIR /src

docker-compose.yml

version: '2'
services:
  nginx:
    image: nginx:latest
    container_name: ng01
    ports:
      - "8000:8000"
    volumes:
      - ./src:/src
      - ./config/nginx:/etc/nginx/conf.d
    depends_on:
      - web
  web:
    build: .
    container_name: dg01
    command: bash -c "python manage.py makemigrations && python manage.py migrate && gunicorn helloworld_project.wsgi -b 0.0.0.0:8000"
    depends_on:
      - db
    volumes:
      - ./src:/src
    expose:
      - "8000"

  db:
    image: postgres:latest
    container_name: ps01

helloworld_project是:

upstream web {
  ip_hash;
  server web:8000;
}

# portal
server {
  location / {
        proxy_pass http://web/;
    }
  listen 8000;
  server_name localhost;
}

requirements.pip

Django==2.0.5
gunicorn==19.7.1
psycopg2==2.7.3.2

所有项目结构为:

enter image description here

为什么localhost:8000和/或localhost:80在mozilla firefox上运行时说连接重新启动,而我却无法查看该应用程序?

1 个答案:

答案 0 :(得分:0)

工作!

解决方案是将我的8001 host port重定向到8000 docker port。可能是我的笔记本电脑正在使用该端口。 5432 postgreSQL port也发生了同样的事情。

在Winwdos中,docker toolbox也可以使用,但是建议通过浏览器连接以使用Kitematic(docker工具箱默认提供的软件工具),因为它可以快速连接到{{1 }}。在Windows中,docker web server IPdocker中运行,因此您无法使用VirtualBox进行连接,因为它重定向到虚拟机,而不重定向到在此localhost上运行的容器。 / p>

相关问题