gpt4 book ai didi

python - boot2docker、docker、mac os x 上的 django

转载 作者:太空宇宙 更新时间:2023-11-03 13:40:56 24 4
gpt4 key购买 nike

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

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

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

这是图像和容器信息; docker_test 是我的应用

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

最佳答案

whenever I visit container-ip:8000 or http://localhost:8000, it doesn't work

参见 docker/issues/4007 : 在 OSX 上使用 boot2docker 时需要使用端口转发。
这意味着VM boot2docker 需要将端口8000 转发给OSX 实际主机。
mentioned it here :

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

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

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

This script ,例如,可以提供帮助。

如“Boot2docker on OsX”所示,localhost 将不起作用:

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.

Get the address of the boot2docker VM.

$ boot2docker ip
192.168.59.103

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

关于python - boot2docker、docker、mac os x 上的 django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31353157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com