4

I have looked through the questions on this site, but I have not been able to fix this problem.

I created and ran an image of my django app, but when I try to view the app from the browser, the page does not load (can't establish a connection to the server)

I am using docker toolbox, I am using OS X El Capitan and the Macbook is from 2009.

The container IP is: 192.168.99.100

The django project root is called "Web app" and is the directory containing manage.py. My Dockerfile and my requirements.txt files are in this directory.

My dockerfile is:

FROM python:3.5 WORKDIR /usr/src/app COPY requirements.txt ./ RUN pip install -r requirements.txt COPY . . EXPOSE 8000 CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] 

My requirements.txt has django and mysqlclient

My django app uses Mysql, and I tried to view the dockerized django app in the browser with and without linking it to the standard mysql image. In both cases, I only see the following error:

problem loading page couldn't establish connection to server

When I did try linking the django container to the mysql container I used:

docker run --link mysqlapp:mysql -d app 

Where mysqlapp is my mysql image and 'app' is my django image.

In my django settings.py, the allowed hosts are:

ALLOWED_HOSTS: ['localhost', '127.0.0.1', '0.0.0.0', '192.168.99.100'] 

Again, the image is successfully created when I used docker build, and it is successfully run as a container. Why is the page not loading in the browser?

3 Answers 3

4

I suggest to use yml file and docker compose. Below is a template to get you started:

[Dockerfile]

FROM python:2.7 RUN pip install Django RUN mkdir /code WORKDIR /code COPY code/ /code/ 

where your files are located in code directory.

[docker-compose.yml]

version: '2' services: db: image: mysql web0: build: . command: python manage.py runserver 0.0.0.0:8000 ports: - "8000:8000" depends_on: - db 

There might be a problem with your working directory path defined in Dockerfile. Hope above helps.

Sign up to request clarification or add additional context in comments.

Comments

3

Solution provided by salehinejad seems to be good enough ,although i have not tested it personally but if you do not want to use yml file and want to go your way then you should expose the port by adding

-p 0:8000

in your run command

So your should look like this :

docker run -p 0:8000 --link mysqlapp:mysql -d app 

Comments

0

I suspect you have not told Docker to talk to your VM, and that your containers are running on your host machine (if you can access at localhost, this is the issue).

Please see this post for resolution:

Connect to docker container using IP

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.