i am trying to make my website (which is from a docker container, inside a google cloud platform vm) and the first page work just fine.
but when i try to access any other page than the home one, for exemple: http://34.130.236.145:25556/metainfo/1
it says
requests.exceptions.ConnectionError: HTTPConnectionPool(host=34.130.236.145,
port=25555): Max retries exceeded with url: /metainfo/1 (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7cee6c119100>:
Failed to establish a new connection: [Errno 111] Connection refused'))
this is my code for the domain:
@app.route('/metainfo/<file_number>')
def getMetaPageInfo(file_number): #pragma: no cover
response = requests.get('http://' + BACK_END_IP + ':' + BACK_END_PORT + '/metainfo/'
+ file_number)
data = None
if response.status_code == 200:
data = json.loads(response.content.decode('utf-8'))
else:
data = {'message': 'Impossible de contacter l'api'}
return page_template('Méta-Information', data)
and the code that calls the two variables you see:
app = Flask('memoryanalysisfe')
TEMPLATE_FOLDER = app.root_path + '/project/app/templates/'
BACK_END_IP = 'backend'
BACK_END_PORT = '25555'
For more clarifications, BACK_END_IP = ‘34.130.236.145’ is set like this because if i put anything else it give me:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='backend', port=25555):
Max retries exceeded with url: /bitmap/1 (Caused by NameResolutionError("
<urllib3.connection.HTTPConnection object at 0x7f6c74909f10>: Failed to resolve
'backend' ([Errno -2] Name or service not known)"))
also, my docker file for my front end is
FROM demers/python420w4a
COPY ./requirements.txt /
RUN pip3 install -r /requirements.txt
RUN apt-get update -y
RUN apt-get install -y xxd
WORKDIR /var/lib
CMD ["./run.sh", "./project/app/memoryfront.py", "25556"]
and this is for my backend:
FROM demers/python420w4a
COPY ./requirements.txt /
RUN pip3 install -r /requirements.txt
RUN apt-get update -y
RUN apt-get install -y xxd
WORKDIR /var/lib
CMD ["./run.sh", "./project/main/memoryapi.py", "25555"]
and this is my ./startDocker.sh script:
#!/bin/bash
sudo aa-remove-unknown
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
vol_name=memory_ad_vol
api_cont_name=memoryapi_ad_cnt
api_image_name=memoryapi_ad_img
website_cont_name=memorywebsite_ad_cnt
website_image_name=memorywebsite_ad_img
echo "Début du lancement de l'api et du Site Web dans Docker"
echo "Le nom pour l'image de l'api: $api_image_name"
echo "Le nom pour l'image du Site Web: $website_image_name"
echo "Le nom du volume où vont ce trouver les images et conteneurs: $vol_name"
echo "Le nom pour le conteneur de l'api: $api_cont_name"
echo "Le nom pour le conteneur du Site Web: $website_cont_name"
###CLEANUP
echo "Stoping everything"
docker-compose -f "$SCRIPT_DIR/docker-compose.yml" down
###REBUILD
echo "Creating everything"
docker-compose -f "$SCRIPT_DIR/docker-compose.yml" up -d
and lastly, my docker-compose.yml file:
version: '3.8'
services:
memory_Backend:
build:
context: ./
dockerfile: ./project/docker/dockerfilebackend
image: memoryapi_ad_img
volumes:
- ./:/var/lib
ports:
- 25555:25555
memory_Frontend:
build:
context: ./
dockerfile: ./project/docker/dockerfilefrontend
image: memorywebsite_ad_img
volumes:
- ./:/var/lib
ports:
- 25556:25556
Thanks in advance for helping me!
I just changed my port from 15555:25555 to 25555:25555 and put my ip adress for the backend stuff in the variable.