Docker connection refused hanging Django

When I run my container, it just hangs on the next line and if I write

curl http://0.0.0.0:8000/

I get

Failed to connect to 0.0.0.0 port 8000: Connection refuse

This is my dockerfile

FROM python:3.6.1

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

RUN pip3 install -r requirements.txt

CMD ["python3", "dockerizing/manage.py", "runserver", "0.0.0.0:8000"]

I also tried doing it through a docker-compose.yml file and again nothing happens, I´ve searched a lot and haven´t found a solution, this is the docker-compose.yml

version: "3"
services:
  web:
    image: app1
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "8000:8000"
    networks:
      - webnet
networks:
  webnet:

By the way, if I run docker ps with myapp image I get this:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
e9633657f060        app1                "python3 dockerizi..."   5 seconds ago       Up 5 seconds                            friendly_dijkstra

When I deploy the service with the django-compose.yml and docker ps I get this:

`MacBook-Pro-de-Jesus:docker-django Almaral$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
13677a71d9d5        app1:latest        "python3 dockerizin..."   15 seconds ago      Up 11 seconds                           getstartedlab_web.1.cq3zqmpfsii5g6m5r9qsnmtb1
c6693118ef70        app1:latest        "python3 dockerizin..."   16 seconds ago      Up 12 seconds                           getstartedlab_web.4.r472oh80s4zd1yymj447f1df6
f3822e47970b        app1:latest        "python3 dockerizin..."   16 seconds ago      Up 12 seconds                           getstartedlab_web.2.lkp43v9h30esjohcnf3pe31hi
f66a4038ebdf        app1:latest        "python3 dockerizin..."   16 seconds ago      Up 12 seconds                           getstartedlab_web.5.xxu01ruebd84tnlxmoymsu0vo
e3d31c419c11        app1:latest        "python3 dockerizin..."   16 seconds ago      Up 13 seconds                           getstartedlab_web.3.uqswgirmg22sjnekzmf5b4xo7`

Upvotes: 2

Views: 5368

Answers (2)

Håken Lid
Håken Lid

Reputation: 23074

Your docker ps output shows nothing in the PORTS column. That means that there's no port forwarding from the host to the container.

[...]     STATUS          PORTS                     NAMES
[...]     Up 5 seconds                              friendly_dijkstra

If you use the command docker run to run your container, you should explicitly specify port number both on host and on the container using the command option -p hostPort:containerPort

docker run -p 8000:8000 app1

Now, running docker ps should show port forwarding.

[...]     STATUS          PORTS                     NAMES
[...]     Up 5 seconds    0.0.0.0:8000->8000/tcp    friendly_dijkstra

If you are using docker-compose to start your containers, the host and container ports are already configured in your docker-compose.yml file, so you don't need a command line option.

docker-compose up web

To use docker compose, you have to install it on the host. It's a python module, so you can install it with pip pip install docker-compose

Upvotes: 6

Mathieu TORTUYAUX
Mathieu TORTUYAUX

Reputation: 31

Into your docker-compose config file, modify your port redirection from: 8000:8000 to 127.0.0.1:8000:8000

Upvotes: 0

Related Questions