2
我有一個django應用程序,我需要在Amazon的EC2容器服務上部署。同時,爲了測試部署,我試圖首先在本地部署Docker容器,但即使運行簡單的演示django應用程序,我也無法在localhost:8000上看到該頁面。看不到在本地主機上的docker容器中運行的django網站
這是我的設置。
創建一個泊塢窗機:
$ eval "$(docker-machine env testmachine)"
我成立了一個Dockerfile爲我的測試容器:
FROM ubuntu
RUN echo "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main universe" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install python-pip -y
RUN pip install django
RUN mkdir django_test
RUN cd django_test && \
django-admin.py startproject django_test .
然後我
$ docker-machine create --driver virtualbox testmachine
這個設置我的環境後致電
$ docker build -t dockertest .
... builds successfully
$ docker run -d -i -t -p 8000:8000 dockertest
cbef144ac068eb61b0c3e032448cc207c8f0384a9a67a710df6d9beb26d2ab32
$ docker attach cbef144ac068eb61b0c3e032448cc207c8f0384a9a67a710df6d9beb26d2ab32
[email protected]:/# cd django_test
[email protected]::/django_test# python manage.py runserver 0.0.0.0:8000
成功啓動服務器的容器的0.0.0.0:8000/。
但是,當我嘗試在我的瀏覽器中轉到localhost:8000時,出現「此網頁不可用」。我錯過了什麼?
對於那些不使用docker-machine的人,可以使用這個命令來獲取你的容器的真實IP地址 - docker inspect --format'{{.NetworkSettings.IPAddress}}'CONTAINER_ID' – mainframer