0

#Docker compose file

version: "3.4"  # optional since v1.27.0
services:
  
  flaskblog:
    build:
      context: flaskblog
      dockerfile: Dockerfile
    
    image: flaskblog
    restart: unless-stopped
    environment:
      APP_ENV: "prod"
      APP_DEBUG: "False"
      APP_PORT: 5000
      MONGODB_DATABASE: flaskdb
      MONGODB_USERNAME: flaskuser
      MONGODB_PASSWORD: 
      MONGODB_HOSTNAME: mongodbuser
    volumes:
      - appdata:/var/www
    depends_on:
      - mongodb
    networks:
      - frontend
      - backend

  mongodb:
    image: mongo:4.2
    #container_name: mongodb
    restart: unless-stopped
    command: mongod --auth
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: 
      MONGO_INITDB_DATABASE: flaskdb
      MONGODB_DATA_DIR: /data/db2
      MONDODB_LOG_DIR: /dev/null
    volumes:
      - mongodbdata:/data/db2
      #- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
    networks:
      - backend
networks:
  
  backend:
    driver: bridge     

volumes:
  mongodbdata:
    driver: local
  appdata:
    driver: local
 

#Flask container file

FROM python:3.8-slim-buster
#python:3.6-stretch

LABEL MAINTAINER="Shekhar Banerjee"

ENV GROUP_ID=1000 \
    USER_ID=1000 \
    SECRET_KEY="4" \
    EMAIL_USER="dankml.com" \
    EMAIL_PASS="nzw"



RUN mkdir /home/logix3
WORKDIR /home/logix3
ADD . /home/logix3/

RUN pip install -r requirements.txt
RUN pip install gunicorn

RUN groupadd --gid $GROUP_ID www
RUN useradd --create-home -u $USER_ID --shell /bin/sh --gid www www

USER www

EXPOSE 5000/tcp


#CMD ["python","run.py"]


CMD [ "gunicorn", "-w", "4", "--bind", "127.0.0.1:5000", "run:app"]

These are my docker-compose file and Dockerfile for an application . The container for MongoDB and Flask are working fine individually, but when I try to run them together, I do not get any response on the localhost, There are no error messages in the logs or the containers

Curl in the system gives this :

$ curl -i http://127.0.0.1:5000 curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused

Can anyone suggest how do I debug this ??

**Only backend network is functional

[
    {
        "Name": "mlspace_backend",
        "Id": "e7e37cad0058330c99c55ffea2b98281e0c6526763e34550db24431b30030b77",
        "Created": "2022-05-15T22:52:25.0281001+05:30",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "12c50f5f70d18b4c7ffc076177b59ff063a8ff81c4926c8cae0bf9e74dc2fc83": {
                "Name": "mlspace_mongodb_1",
                "EndpointID": "8278f672d9211aec9b539e14ae4eeea5e8f7aaef95448f44aab7ec1a8c61bb0b",
                "MacAddress": "02:42:ac:14:00:02",
                "IPv4Address": "172.20.0.2/16",
                "IPv6Address": ""
            },
            "75cde7a34d6b3c4517c536a06349579c6c39090a93a017b2c280d987701ed0cf": {
                "Name": "mlspace_flaskblog_1",
                "EndpointID": "20489de8841d937f01768170a89f74c37ed049d241b096c8de8424c51e58704c",
                "MacAddress": "02:42:ac:14:00:03",
                "IPv4Address": "172.20.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "backend",
            "com.docker.compose.project": "mlspace",
            "com.docker.compose.version": "1.23.2"
        }
    }
]

I checked the logs of the containers. no errors found, flask engine seem to be running but the site wont run , even curl won't given any output

4
  • show su docker inpect network forntend and backend. Commented May 15, 2022 at 17:46
  • Added in the question Commented May 15, 2022 at 17:52
  • You need to use gunicorn --bind 0.0.0.0:5000. In general, if you set something in a Docker container to bind or listen to only 127.0.0.1, it won't be reachable from outside its container. See for example Docker-compose/Nginx/Gunicorn - Nginx not working. Commented May 16, 2022 at 0:07
  • I get your point, but the in dockerfile when gunicorn --bind 0.0.0.0:5000 is replaced with command CMD ["python","run.py"] ,it does not specify any address, there also the same issue occurs Commented May 20, 2022 at 5:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.