微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

创建了一个安装nginx,python,uwsgi和django的docker.如何在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, [email protected]

# 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的虚拟机,所以我在客户操作系统中运行了docker.

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容器中的/jrc中的djangoapp?

我的主机操作系统是Mac OS X Mavericks.

我的客户操作系统是Ubuntu 14.04.

我的docker在guest虚拟机操作系统中运行.

请指教.

解决方法:

在您的docker文件中定义您将公开的网络端口以进行外部访问,如下所示:

EXPOSE 80

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

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

docker run -p 80:80 ...

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

请注意,它基本上是

host-port:container-port

在此之后,您可以打开浏览器,输入端口80的Docker主机(ubuntu服务器)的IP,并且您在容器上;)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐