boot2docker,docker,django在mac os x上 [英] boot2docker, docker, django on mac os x

查看:145
本文介绍了boot2docker,docker,django在mac os x上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Mac OS X上的docker中运行一个Django应用程序。我已经使用 get-started 教程安装了docker。

I want to run a Django app in docker on Mac OS X. I have installed docker using the get-started tutorial.

我在Docker-library中引用Django文档来构建映像, https://github.com/docker-library/docs/tree/master/django ,我将Dockerfile添加到一个新的Django项目文件夹中

I refer to the Django doc in docker-library to build image, https://github.com/docker-library/docs/tree/master/django, I add the Dockerfile in a new Django project folder

问题是我构建映像并成功运行容器,但是每当我访问 container-ip:8000 http:// localhost:8000 ,它不工作。
任何人都有解决方案?

The problem is I build the image and run the container successfully but whenever I visit container-ip:8000 or http://localhost:8000, it doesn't work. Anyone have solutions?

这里是图片和容器信息; docker_test 是我的应用程序

Here are the images and container info; docker_test is my app

REPOSITORY          TAG                 IMAGE ID            CREATED         VIRTUAL SIZE
docker_test         latest              fd6ceebc0c58        13 hours ago        761.5 MB
django              onbuild             9cbcfd71d759        30 hours ago        728.6 MB

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
cbf98a73ea0a        docker_test         "python manage.py ru   26 minutes ago      Up 26 minutes       0.0.0.0:8000->8000/tcp   docker_app


推荐答案


每当我访问container-ip:8000或 http:// localhost:8000 ,它不工作

请参阅 docker / issues / 4007 :在OSX上使用boot2docker时,需要使用端口转发。

这意味着VM boot2docker需要将端口8000转发到OSX实际主机。

I 在此提及

See docker/issues/4007: you would need to use port forwarding when using boot2docker on OSX.
That means the VM boot2docker needs to forward the port 8000 to the OSX actual host.
I mentioned it here:

$ VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port8000,tcp,,8000,,8000";




如果vm已经在运行,您应该运行另一个命令:

If the vm is already running, you should run this other command:



$ VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-port8000,tcp,,8000,,8000";

这个脚本,例如,可以帮助。

OsX上的Boot2docker localhost 将无法正常工作: p>

As shown in "Boot2docker on OsX", localhost wouldn't work:


它不起作用的原因是您的 DOCKER_HOST 地址不是 localhost address( 0.0.0.0 ),而是boot2docker VM的地址。

The reason it doesn’t work is your DOCKER_HOST address is not the localhost address (0.0.0.0) but is instead the address of the boot2docker VM.

获取boot2docker VM的地址。

Get the address of the boot2docker VM.



$ boot2docker ip
192.168.59.103




输入 http://192.168.59.103:8000 您的浏览器中的地址。

Enter the http://192.168.59.103:8000 address in your browser.

这篇关于boot2docker,docker,django在mac os x上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆