I’ve been unable to use Docker to connect to a localhost on an AWS EC2 instance (and I’ve been trying for 4 days now).
I’m running an AWS Linux EC2 Instance, where I’ve already installed all the dependencies, uploaded the 1 python script with the helper functions that utilize these dependencies (helper_functions.py), and the FastAPI script (main.py). My directory is called r_app
, and it looks like:
helper_functions.py main.py __pycache__ Dockerfile leptonica-1.75.1 photo_1.jpg
I am trying to setup this FastAPI script for production testing purposes, and it has only 1 API call. I want to get my 1 API POST call (that utilizes my helper functions) running and available for access on my brower’s localhost (so connecting to the EC2 Instance).
Inside of main.py
:
from fastapi import FastAPI, File, UploadFile, Form
from pydantic import BaseModel
import numpy as np
import cv2
from helper_functions import process_image
app = FastAPI()
@app.post('/file')
def _file_upload(
my_file: UploadFile = File(...),
width: int = Form(...),
height: int = Form(...),
):
image_bytes = my_file.file.read()
decoded = cv2.imdecode(np.frombuffer(image_bytes, np.uint8), -1)
pg_image = cv2.resize(decoded, (width, height))
new_dict = process_image()
return {
"name": my_file.filename,
"new_dict": new_dict
}
I entered the following in my Dockerfile:
FROM ubuntu:18.04
EXPOSE 80
CMD ["ubuntu", "main.py"]
(I have no COPY or RUN statements since I have already manually included all the neccessary dependencies and files in my EC2 instance)
But after I build the image container, and when I run this in the command line
docker run -t -i -p 80:80 getting_started
I get the error
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "ubuntu": executable file not found in $PATH: unknown.
Any help or suggestions is appreciated; thanks so much for helping me clear this roadblock!