I'm trying to setup pythons django inside a dockerized environment


FROM python:3.5-slim
RUN mkdir /code
RUN pip install --upgrade pip
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

I build this to django-app.


  container_name: django
  image: django-app:latest
    - "8000:8000"
    - ./config/startup.sh:/startup.sh
    - ./app:/code
  command: /bin/sh /startup.sh


cd /code
django-admin.py startproject djagento
echo "Creating Project djagento"
cd djagento
python manage.py runserver

I am using ubuntu 14.04 LTS as my host system

docker exec -it django bash $curl is succesfull.

I am getting the ip of my container with docker inspect django

    "Gateway": "",
    "IPAddress": ""

But when trying to curl or curl or curl I am not able to get anything but connection reset


docker ps

baada462ae72        django-app:latest   "/bin/sh /startup.sh"   6 seconds ago       Up 5 seconds>8000/tcp   django

*ON another Port, same result *

CONTAINER ID        IMAGE               COMMAND                 CREATED              STATUS              PORTS                    NAMES
a9d99ee563e5        django-app:latest   "/bin/sh /startup.sh"   About a minute ago   Up About a minute>8000/tcp   django


2 Answers 2


For anyone stumbling upon this, you have to run the django server on inside the docker container, simply adding python django-admin runserver in my startup.sh fixed this for me

  • I also needed to do this, but I also had to add ALLOWED_HOSTS = [ '*' ] to my settings.py file in Django.
    – mherzog
    Jun 15, 2023 at 0:28

Is there anything else on your machine using port 8000? Try changing the port to 8005 or 9005 etc on the host machine. I tend to hate using the same port in general just because of confusion it sometimes causes.

In your dockerfile use

   - '8005:8000'



  • run docker-compose up -d
  • run docker ps
  • See if you see>8000/tcp for the container under PORTS.

Then try curling on the IP on port 8005.

If that still doesn't work check your IPTables on your container. Have you locked port 8000 to local only by accident?

  • I tried this but it is not working on another port as well, I updated the docker ps output above
    – xhallix
    Feb 16, 2016 at 21:24
  • Maybe you can let me know how I check if I locked a port to my local machine?
    – xhallix
    Feb 16, 2016 at 21:29
  • Try curling localhost:8005 see what it says. Note do this from your machine not within the container. Also though it looks like no ports are showing up in your docker ps which is the biggest problem. Can you paste your entire docker ps output? That doesn't seem like a complete copy. Feb 16, 2016 at 21:33
  • me@box-VirtualBox:~/Documents/DockerImages/django-docker$ curl localhost:8005 curl: (56) Recv failure: Connection reset by peer me@box-VirtualBox:~/Documents/DockerImages/django-docker$ curl curl: (52) Empty reply from server
    – xhallix
    Feb 16, 2016 at 21:36
  • I've updated docker ps this in my question above
    – xhallix
    Feb 16, 2016 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .