带有Docker的GCP VM Django项目,无法访问端口

时间:2018-06-19 19:29:26

标签: python django docker google-cloud-platform containers

我正在GCP VM实例上运行Django项目,

我的Dockerfile是:

FROM python:3.5
RUN apt-get update 
USER root
WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
WORKDIR /app/etalentNET
EXPOSE 8000
CMD ["python", "manage.py", "makemigrations"]
CMD ["python", "manage.py", "migrate"]
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

我的doker-compose.yaml是:

version: '3'

services:
  db:
    image: sqlite3
  web:
    build:
      image: demo:latest
      dockerfile: Dockerfile
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
     depends_on:
      - db

当我运行docker run -p 8000:8000 demo时,除了容器没有显示任何内容。

CONTAINER ID   IMAGE   COMMAND       STATUS       PORT
ef4585c1e580   demo   "python ma…"   Up 12 hours  0.0.0.0:8000->8000/tcp          

我尝试通过<host_ip>:8000访问它,但没有ERR_CONNECTION_TIMED_OUT

我正在Ubuntu 16.04Django-2.0.6的GoogleCloud机器上运行。

运行sudo netstat -lp --inet

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
PID/Program name
tcp        0      0 *:ssh                   *:*                     LISTEN      1629/sshd       
udp        0      0 *:bootpc                *:*                                 967/dhclient    
udp        0      0 etalent-net-machine:ntp *:*                                 1627/ntpd       
udp        0      0 localhost:ntp           *:*                                 1627/ntpd              

0 个答案:

没有答案