Forest header image

Symfony Finland
Random things on PHP, Symfony and web development

Serverless PHP with Docker(file) and Zeit▲now... Uhm, what?

Serverless Architectures are the hottest thing right now. Not a lot of people know exactly what they are and if they really need them, but everyone's onboard because they're afraid they're left behind.

The largest players for serverless platforms are Amazon, Google and Microsoft, but now a small player, Zeit, allows Dockerfile based serverless deployments.

The term serverless architectures is deceiving. You're not leaving the client-server architecture of the web and changing it to some peer to peer technology. It means that you're deploying applications with limited scope "somewhere" and often only pay when they are executed.

For the sake of cool or confusion, these simple applications are known as "functions", because of their limited scope. All three big cloud computing mainframes" Amazon AWS, Google Cloud Computing and Microsoft Azure have their own flavours of Serverless platforms for executing functions build in different languages:

In essense each of these allow the exactly same thing, which is building simplistic microservices. The microservices trend itself has been around for a number of year and has proven to be a successful solution for large web companies.

They employ a number of teams that build services in the technology best suited for each tasks. The teams build stand alone services that are consumed by other teams, partners or other external developers. These microservices are then architected into functional systems that together form complex operations.

This architecture can be successful, but is no silver bullet as orchestrating tens or hundreds of services can itself be challenging. And building up a large number of external dependencies on the web is no different from excess library dependencies :)

Zeit ▲now and Dockerfile support

A tiny startup Zeit today announced that their serverless deployment product offering is getting support for the Dockerfile format, breaking them out of their JavaScript-only world:

With now 0.20.0 we are introducing the fastest and simplest solution to deploy, build and scale containers in the cloud. If your directory contains a Dockerfile, just type now to deploy it.
- Introducing Dockerfile support

A Dockerfile is a simple text document that contains all the commands to put together an image that can be executed on the Docker platform. User can create automatic builds that run a number of commands within the Dockerfile of a project. Because of this, ▲now users can essentiall run any programming languages and even exotic extensions on the platform.

As one example in the blog post, they demonstrate creating a simple Docker image that runs Apache2 with libapache-mod-php. This allows you to create and deploy simple PHP applications using their command line tool and a standard Dockerfile:

FROM kstaken/apache2
LABEL name "my-docker-deployment"
RUN apt-get update && apt-get install -y php5 libapache2-mod-php5 php5-mysql php5-cli && apt-get clean && rm -rf /var/lib/apt/lists/*
COPY index.php /var/www
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

With the above Dockerfile and a single index.php script in place, you can deploy your PHP hello world "somewhere" and not worry about where it's running and how. Big deal or just return to shared hosting? Time will tell, but cost can be a factor pushing towards serverless architectures in the future.

The key thing here is that the Dockerfile is created on their server and not in the development environment as usual. The process of development and deployment on now has a contemporary feel to it and worth trying out, even if you don't plan to use the service: Get started with now

Conclusion

The serverless architecture functions can be seen as an amalgamation of the cloud and microservices trends. Common tasks like user management, emails or billing can be packaged into products and reused, where now a lot of microservices are built in-house for specific tasks. These can range from simple services to something very complex as Active Directory as a Service from Azure.

Executable functions built on serverless platforms on the other hand allow you to create custom functions that have an de-facto deployment plan that allows you to take hosting worries out of your equation. Together with the sophisticated browser built applications built allow composing complex systems on the client side without a central integration server.

While the term serverless architectures certainly carries quite a bit of hype (or bollocks, really) and you might think of them as a glorified simple PaaS. But it's certainly something to keep tabs on. And with the Dockerfile compatibility from Zeit ▲now you have quite a bit of freedom that the larger players currently don't offer.

Learn more:


Written by Jani Tarvainen on Monday August 15, 2016
Permalink - Tags: php, docker

« Consider Docker for your Symfony projects - Symfony Bundle Spotlight: EasyLogHandler, eZ Migration Bundle, Netgen Layouts and Sylius »