user994165
user994165

Reputation: 9502

docker-compose up not forwarding port

I have the following files. When I run docker-compose up -d and exec into the docker container, I am able to run http://127.0.0.1:5000 and get back results. From the host I get back:

user@ubuntu:~/projects/grip/glm-plotter$ curl -v http://localhost:5000
* Rebuilt URL to: http://localhost:5000/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.58.0
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

If I run the docker-compose command without a -d, it starts up but from a separate terminal I also get back empty results.

docker ps (When running without -d)

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
237b0a7f8710        glm-plotter_web     "python3 glm-plotter…"   16 minutes ago      Up 24 seconds       0.0.0.0:5000->5000/tcp   glm-plotter_web_1

I'm not sure if the process should be listed under "docker-proxy":

user@ubuntu:~$ sudo netstat -tulpn | grep 5000 
tcp6       0      0 :::5000                 :::*                    `LISTEN      13785/docker-proxy`  

Dockerfile

FROM library/python:3.6-stretch
RUN apt-get update && apt-get install -y python3
RUN apt-get install -y python3-pip
RUN apt-get install -y build-essential

COPY requirements.txt /
RUN pip3 install --trusted-host pypi.org -r /requirements.txt
RUN pip3 install --upgrade numpy
ADD ./glm-plotter /code
WORKDIR /code
RUN ls .
CMD ["python3", "glm-plotter.py"]

docker-compose.yml

version: "3"
services:
  web:
    volumes:
      - ~/.aws:/root/.aws
    build: .
    ports:
      - "5000:5000"

Upvotes: 1

Views: 2888

Answers (1)

Jan Garaj
Jan Garaj

Reputation: 28626

Your glm-plotter.py is listening only on the localhost in the container. Your app must be listening on all interfaces in the container - TCP host 0.0.0.0, not just locahost/127.0.0.1 - you need to fix your python code.

It is a common issue - flask example: flask is working inside container but not when I port forward it

Upvotes: 7

Related Questions