Serverless implementations are usually Cloud Deployment-specific, AWS Lambda being the most popular implementation. However, there are some advantages to using containers. Let's look at them:
Dependency Management
Containers allow you to package all dependencies and libraries directly into the image, making it easier to manage complex dependency structures.
Consistency
All of the necessary provisions and configurations are part of containers, ensuring consistency across deployments.
Larger Function Size
This, I believe, is the biggest benefit. Container-based Lambda functions can be up to 10GB in size, compared to the 250MB limit for zip packages. However, there is a additional cost associated with containers.
Security Posture
Containers can be scanned for vulnerabilities and software composition analyses much more easily than Lambdas.
Looks good, but what's the issue?
Cold Start Performance
For larger containers, cold start times can be significantly impacted. Although AWS has improved in this area, it can still be a concern for time-sensitive applications.
Lambda Layers and Extensions
This is a limitation when using containers. However, for a company that uses mainly Lambdas for a wide variety of projects which use the same programming language, this can be a considerable advantage.
Additional Cost
Using containers usually incurs additional costs, as it requires a different hosting option.
Should You Use Containers or Not?
All that said, I believe containers may not be suitable for most Serverless use cases. Why? Because cloud providers offer tailor-made trigger functions that need to be incorporated into the code, so the advantage of having them as containers, which the added ability for them to be run anywhere, is lost. For Azure, it's the Azure Function wrapper, and for AWS, it's the Lambda Handler. It's often easier to add these wrappers to existing implementations when deploying them to serverless environments. However, this approach undermines some of the key advantages of containers.If you need to create a custom application for serverless environments, it's generally better to go with the cloud provider's native approach for maximum performance and integration. This allows you to fully leverage the provider-specific features and optimizations, which can lead to better overall efficiency and effectiveness.
As an example, I have used Azure to create and test a container-based Serverless application. You can find it here. It still uses Azure specific triggers to APIs.