Your problem may be related to your container HTTPS configuration.
Please, consider review the documentation provided by Microsoft when describing how to develop ASP.NET Core Applications with Docker over HTTPS and Hosting ASP.NET Core images with Docker Compose over HTTPS. This related question could be of help as well.
Basically, you need to provide different environment configuration properties that define, respectivelly, the URLs valid for your application, the HTTPS listen port, the path to the SSL certificate to use, and the password that protects that certificate:
ASPNETCORE_URLS="https://+;http://+"
ASPNETCORE_HTTPS_PORT=8001
ASPNETCORE_Kestrel__Certificates__Default__Password="password"
ASPNETCORE_Kestrel__Certificates__Default__Path=\https\aspnetapp.pfx
As indicated in the GCP documentation, you could provide this environment information using the GCP Web Console or the gcloud
CLI, in the later case using either the --container-env
or the --container-env-file
flags.
As indicated in the aforementioned SO question, I think you could take advantage of the multi stage Docker build process to pass this environment information as well.
Due to the fact that the containers deployed in Compute Engine share the host network, please, be sure that you have configured the necessary firewall rules to allow access to your container ports.
In order to access your certificate from your container I think you probably have two options.
On one hand, you can include the certificate in your image as part of the build process. It has the obvious drawback that it will make the certificate more accessible, it is a less secure solution, although it can be mitigated if you deploy your image to a non public repository; in addition, take into account that you still need the password for the pfx, so, with caution, it could be a valid solution.
In addition, as described in the GCP documentation, you can mount a host directory and make it accessible as a volume to your container, and store the certificate in that directory. In certain images, in order to automate the distribution progress, you can use the --metadata
flag and the startup-script
key for instance to provide the necessary information about how to access the certificate. But... where to obtain the certificate in first place? Ideally it may be stored in Google KMS in an encrypted form or perhaps within Google Secrets. This approach is suggested for instance in this article, although I personally have never tried it.
Having said that, in my opinion, instead of trying to customize your container, a better solution will be to configure a HTTPS load balancer in front of your VMs: in addition to high availability and scalability, ease of maintenance, etcetera, regarding the HTTPS configuration, you only need to provide your certificate details when configuring your load balancer frontend; you can request a Google managed certificate as well if necessary.
Please, be aware that if you follow this second option, you do not longer need to configure HTTPS in your application itself, it can safely run on port 80
. The idea is to delegate HTTPS handling to the load balancer and use the load balancer frontend to provide SSL termination, freeing your application from that responsibility.