I have 2 flask applications running on separate containers. When I try to make an API request from one container to another I get the following error :
HTTPConnectionPool(host='0.0.0.0', port=5001): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused'))
Flask app1:
app.route("/", methods=["GET"])
@cross_origin(supports_credentials=True)
def ads():
r=requests.get('http://0.0.0.0:5001/',verify=False)
return jsonify(r.text)
Flask app2:
app.route("/", methods=["GET"])
@cross_origin(supports_credentials=True)
def add2():
return jsonify('Success!')
Docker file for app1:
FROM alpine:latest
RUN apk add --no-cache python3-dev \
&& pip3 install --upgrade pip
WORKDIR /
COPY . .
RUN pip3 --no-cache-dir install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python3"]
CMD ["app.py","--host", "0.0.0.0"]
Docker file for app2:
FROM alpine:latest
RUN apk add --no-cache python3-dev \
&& pip3 install --upgrade pip
WORKDIR /
COPY . .
RUN pip3 --no-cache-dir install -r requirements.txt
EXPOSE 5001
ENTRYPOINT ["python3"]
CMD ["app.py","--host", "0.0.0.0"]
The docker commands used are:
docker run -p 5000:5000 app1
docker run -p 5001:5001 app2
How can I resolve this error without using docker-compose?