Docker VPS work with HTTP but not with HTTPS

73 Views Asked by At

I am trying to host my Flask Rest API from Docker container within a VPS (apache). Its working fine with http but not working with https.

Dockerfile

FROM python:3.11
# Virtual envs not needed inside container
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
COPY . /app
RUN python3 -m pip install -r /app/requirements.txt

EXPOSE 5000
CMD ["flask", "--app=app", "run", "--host=0.0.0.0"]

running $ docker run --rm -it -p 8080:5000 myapp:latest allow me to run http://myapphostwebsite.com:8080/user/12345 on Postman. I could then retrieve data but when using https://myapphostwebsite.com:8080/user/12345, I got this Postman error :

Error: write EPROTO 5543930632:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../../../src/third_party/boringssl/src/ssl/tls_record.cc:242:

And the Docker Log gives this

code 400, message Bad request version ('À\x13À') \x16\x03\x01\x00ü\x01\x00\x00ø\x...

I don't know what to do. How to access my Docker container outside with https?

PS : I used Certbot to setup SSL on my VPS

1

There are 1 best solutions below

1
liyangxia On

This is because Alpine mirrors do not have CA certificates installed by default. You can fix this issue by following the steps below:

apk add --no-cache ca-certificates