Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boot2docker, docker, django on mac os x

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

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

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?

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
like image 418
wayne Avatar asked Mar 15 '23 10:03

wayne


1 Answers

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

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";

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

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

This script, for example, can help.

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

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.

like image 181
VonC Avatar answered Mar 25 '23 03:03

VonC