创建了一个安装 nginx、python、uwsgi 和 django 的 docker。如何在 VM 中测试它?

Have created a docker that installs nginx, python, uwsgi and django. How do I test it within a VM?

我使用 docker 创建了 following project

这是 Dockerfile

############################################################
# Purpose   : Dockerize Django App to be used in AWS EC2
# Django    : 1.8.1
# OS        : Ubuntu 14.04
# WebServer : nginx
# Database  : Postgres inside RDS
# Python    : 2.7
# VERSION   : 0.1
############################################################

from ubuntu:14.04

maintainer Kim Stacks, kimcity@gmail.com

# make sure package repository is up to date
# this is commented out because it clashes with install build-essential
# run echo "deb http://archive.ubuntu.com/ubuntu trusty main universe" > /etc/apt/sources.list

run apt-get update

# run apt-get upgrade --force-yes -y

# install python
run apt-get install python  --force-yes -y              ## install 2.7
run apt-get install python-setuptools --force-yes -y    ## for python2.7 or above
run apt-get install build-essential --force-yes -y      ##
run apt-get install python-virtualenv --force-yes -y    ## virtual env
run apt-get install python-dev --force-yes -y       ## because ubuntu 14.04 does not have dev version of python 2


# install nginx
run apt-get install \
        nginx \
        --force-yes -y

## copy the nginx config files
COPY ./nginx_configuration/common.conf      /etc/nginx/common.conf
COPY ./nginx_configuration/fastcgi_params   /etc/nginx/fastcgi_params
COPY ./nginx_configuration/nginx.conf       /etc/nginx/nginx.conf
COPY ./nginx_configuration/php.conf         /etc/nginx/php.conf
COPY ./nginx_configuration/default          /etc/nginx/sites-available/default
COPY ./nginx_configuration/php.example      /etc/nginx/sites-available/php.example
COPY ./nginx_configuration/django-app.conf      /etc/nginx/sites-available/django-app.conf

## copy the bash_rc over
# COPY ./bash_files/.bash_profile           /root/.bash_profile

run /etc/init.d/nginx restart


########################################
## Install Django 
## and associated python modules
########################################

# Install pip
RUN easy_install pip

# Add and install Python modules
ADD requirements.txt /src/requirements.txt
RUN cd /src; pip install -r requirements.txt


# Bundle app source
ADD ./djangoapp /src

########################################
## Remove any unwanted packages
########################################
run apt-get autoremove --force-yes -y

我有一个 Ubuntu14.04 的 VM,所以我 运行 docker inside 来宾 OS。

docker build -t django18-python27-ubuntu1404 . ## build docker reponame dockerfilepath

docker run -ti django18-python27-ubuntu1404 sh ## run the docker and go in

一旦我进入docker,我就去/src然后运行uwsgi --ini uwsgi.ini

我的问题是如何在 docker 容器的 /src 中测试 djangoapp?

我的主持人 OS 是 Mac OS X Mavericks。

我的客人 OS 是 Ubuntu 14.04.

我的docker是运行里面客人OS.

请指教

在您的 docker 文件中定义您将暴露给外部访问的网络端口,如下所示:

EXPOSE 80

这会将容器的端口 80 暴露给 docker。

现在您可以告诉 docker 进行 NAT 并将此端口转发到 docker 主机的空闲端口以访问它。像这样:

docker run -p 80:80 ...

这将告诉 docker 将主机端口 80 映射到容器端口 80。

请注意,基本上是

host-port:container-port

在此之后您可以打开浏览器,输入您的 Docker 主机(Ubuntu 服务器)的 IP 地址和端口 80,瞧,您已经在您的容器上了 ;)