Docker cannot access Webserver on host

Solution 1:

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

Solution 2:

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

ports:
   - '8005:8000'

instance.

After:

  • run docker-compose up -d
  • run docker ps
  • See if you see 0.0.0.0:8005->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?