Trouble Deploying Docker image Flask AWS Beanstalker

Viewed 29

I am trying to deploy a machine learning model using flask, then I used docker to build an image, and finally Travis for CI\CD and deploy it on AWS Beanstalk. the Flask application runs well on localhost and docker image run command.

My entire project is here: end2endML

I am having the following problem > 502 Bad Gateway

Until now :

  • It is running on 64bit Amazon Linux 2/3.4.15 -I don't find any other option-
  • I have read about the port 80 or 5000 I have tried both and they failed
  • I read the Log and received this message Error

I have a Dockerfile and Docker-compose.yml for deployment. and they look like this:

FROM python:3.7-slim-bullseye

WORKDIR /app

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install dependencies:
COPY . /app
RUN pip install -r /app/requirements/requirements.txt

EXPOSE 5000

# Run the application:
CMD ["python", "/app/classification_model/application.py"] 


 ---> My docker Compose

# Docker compose for Amazon
version: '3'
services:
  aws_deployment:
    # This function forces Dockerfile
    build:
      # Files (look at the current dir)
      context: .

      # Look for this file
      dockerfile: Dockerfile
    ports:
      - "80:5000"

--> My Travis file 

#autom install a copy of docker 
services:
  - docker

# Do before : -f force -t anynameyouwantforyourimage
before_install: 
  - docker build -t raudez77/end2end-machine-learning -f Dockerfile .

# Run test
# Script contents all script to run
script:
  - docker run raudez77/end2end-machine-learning python test.py -- --coverage

#Deploy into Amazon ElasticBeanstalk
deploy:
  # Use this Saas for deployment
  provider: elasticbeanstalk
  region: "us-west-2"
  # Application name
  app: "docker_titanic"
  # Enviroment
  env: "Dockertitanic-env"
  # Go Services- S3 - look for yout us-west-2 elastickbeanstalk
  bucket_name: "elasticbeanstalk-us-west-2-082124557004"
  bucket_path : "docker_titanic"

  # Create Acces key in Travis
  access_key_id: $AWS_ACCESS_KEY
  secret_access_key: "$AWS_SECRET_KEY"
  on:
    branch: master
  skip_cleanup: true ```
0 Answers
Related