[Django]-Unable to connect to server when running docker django container

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.

๐Ÿ‘คsalehinejad

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 
๐Ÿ‘คemme

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

๐Ÿ‘คzachdb86

Leave a comment