You’re doing it wrong!
You need to split the container into Data and Web or you can use RDS for Postgresql to host data and load-balance among the web containers.
Also, It is not recommended to use cloudflare optimizations as they cause many issues.
And You need to set up your cloudfront URL in the discourse CDN field not the name of the server.