简体   繁体   中英

Can't access through localhost to my web server on docker

I am following this tutorial to achieve a dockerized django app:

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

I am able to build and run the docker image and conatiner without problem.

For example my services from container are in these status:

docker ps

在此处输入图片说明

docker-compose logs web

在此处输入图片说明

docker-compose logs nginx returs nothing

Dockerfile is:

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 is

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 is:

upstream web {
  ip_hash;
  server web:8000;
}

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

requirements.pip is

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

And all the project structure is:

在此处输入图片说明

Why localhost:8000 and/or localhost:80 run with mozilla firefox says the connection is restarted and I am not able to view the app?

Working!

The solution was to redirect my 8001 host port to the 8000 docker port . Probably my laptop was using this port. The same thing happened for 5432 postgreSQL port .

In Winwdos is also working with docker toolbox but to connect throug browser is recommended to use Kitematic (software tool that comes by default with docker toolbox) because it allows to connect quickly to the docker web server IP . In windows docker runs in a VirtualBox , so you can not connect using localhost , because it redirects to the virtual machine and not to the container running on this VM .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM