$30 off During Our Annual Pro Sale. View Details »

Symfony and Docker: a refreshing new experience

Symfony and Docker: a refreshing new experience

Recently, new configurators for Docker and Docker Compose have been added to Symfony Flex.
This means that Symfony can now transparently add the services and PHP extensions needed by your preferred packages!

You want to use Doctrine ORM? So you need a database and the related PDO extension! We’ve got you covered.
You use the mailer? So you want MailCatcher in your development environment? Let’s do this.
You want Panther? so you need Chrome and ChromeDriver! No problem!

But there is more: we now offer you Docker skeletons that take advantage of these new capabilities, and that you can use locally, but also in your CI system and in production!

Kévin Dunglas

December 10, 2021
Tweet

More Decks by Kévin Dunglas

Other Decks in Programming

Transcript

  1. Symfony
    & Docker A new pattern to build fast
    and reliable web APIs
    A refreshing new development
    experience

    View Slide

  2. Kévin Dunglas
    ➔ Co-founder of Les-Tilleuls.coop
    ➔ Symfony Core Team
    ➔ Symfony Docker
    ➔ API Platform
    @dunglas

    View Slide

  3. API, cloud, PHP and JS experts
    ➔ Scop, 100% employee-owned ✊
    ➔ Democratically managed 💬
    ➔ 55 people 🦄
    ➔ France, Tunisia, Morocco 🌎
    [email protected] 💌
    Les-Tilleuls.coop

    View Slide

  4. Docker?!

    View Slide

  5. ➔ An OS-level virtualization platform
    ● Build: Dockerfile
    ● Share: Registry (hub)
    ● Run: Engine
    ➔ Software is packaged in containers
    ● Embedded binaries, libs, config files...
    ● Run in isolation
    ● Share a single OS kernel: ⬆performance
    Docker

    View Slide

  6. Why should you use Docker?
    ➔ Easy onboarding
    ● docker-compose up
    ● No more cumbersome and outdated README files
    ➔ Versioned, same software and configs everywhere: git pull
    ● locally, for the entire team
    ● CI
    ● staging
    ● prod
    ➔ Standardized, industry standard
    ➔ Great tooling, large ecosystem (GitHub Actions, Rancher, K8s...)
    ➔ (Almost) cross platform: Linux, Windows, Mac
    @dunglas

    View Slide

  7. Dockerfile

    View Slide

  8. ➔ Define and run multi-container apps
    ➔ In dev, staging and even prod (single host)
    ➔ Example for a Symfony app:
    ● PHP container
    ● Web server container
    ● DBMS container
    ● Cache server container
    ● …
    Docker Compose

    View Slide

  9. Docker Compose

    View Slide

  10. Docker and
    Symfony:
    an Old Story

    View Slide

  11. 7 years ago @ Sensiolabs
    I’ve been introduced to a brand
    new tool for hipsters during a
    workshop led by Jérémy
    Derussé at Sensiolabs.

    View Slide

  12. 6 years ago @ Les-Tilleuls.coop
    Vincent Chalamon proposed a
    patch adding Docker support to
    API Platform.

    View Slide

  13. 4 years ago
    I started the “Symfony Docker”
    installer and project skeleton
    (co-maintained by Maxime
    Helias).

    View Slide

  14. 2 years ago
    I contributed experimental Flex
    configurators for Docker and
    Docker Compose.

    View Slide

  15. Today @ SymfonyWorld 2021
    ➔ I’m very happy to announce the immediate availability of
    the official
    Symfony Docker integration
    @dunglas

    View Slide

  16. Symfony Flex

    View Slide

  17. Symfony Flex
    ➔ Composer plugin
    ➔ Generates the configuration of newly installed PHP
    packages
    ➔ New: Docker support
    ● Dockerfile: add PHP extensions, libs, binaries
    ● Docker Compose: adds new services
    @dunglas

    View Slide

  18. Docker Compose Flex Configurator

    View Slide

  19. Supported Packages
    Package Image
    symfony/orm-pack postgres
    symfony/mercure-bundle dunglas/mercure
    symfony/panther n/a (Dockerfile only)
    symfony/mailer schickling/mailcatcher
    blackfireio/blackfire-symfony-meta blackfire/blackfire
    More to come: PRs welcome!
    github.com/symfony/recipes

    View Slide

  20. Symfony CLI

    View Slide

  21. Symfony CLI
    ➔ Create new Symfony applications
    ➔ Deploy in SymfonyCloud
    ➔ Local web server, built-in TLS support
    ➔ Integration with Docker Compose
    ➔ Dev environments only
    ➔ Require local installations of PHP and Symfony CLI
    @dunglas

    View Slide

  22. Symfony CLI: Docker Compose Support

    View Slide

  23. Symfony CLI: Docker Compose Support

    View Slide

  24. Symfony Docker
    Skeleton

    View Slide

  25. Symfony Docker
    ➔ Docker-based skeleton and installer
    ➔ Prod ready
    ➔ Compatible with the Flex configurators
    ➔ No local dependencies, you just need Docker
    ➔ No bloat, readable config: only 2 containers
    ● PHP
    ● Web server
    ➔ Automatic TLS certificate generation and renewal
    ➔ Native support for Mercure and Vulcain
    @dunglas

    View Slide

  26. GitHub Template (optional)

    View Slide

  27. Get Started

    View Slide

  28. Deploy in prod (single host)

    View Slide

  29. Dockerfile Flex Configurator
    Support

    View Slide

  30. docker-compose exec php \
    composer req orm

    View Slide

  31. ➔ Free and Open Source web server
    ➔ Secure and super fast, written in Go
    ➔ Extensible
    ➔ Native PHP FPM support 😍
    ➔ Automatic HTTPS, even for localhost
    ➔ HTTP/3!
    ➔ Mercure, Vulcain, OAuth, OIDC
    modules
    ➔ Cloud native
    (API, hot config reloading…)
    Caddy Inside

    View Slide

  32. Kubernetes

    View Slide

  33. ➔ Free and Open Source container
    orchestration system
    ➔ Unlike Docker Compose: native
    cluster support
    ➔ Allows to scale deployments (with
    autoscaling support)
    ➔ Industry standard
    ➔ Managed clusters offered by AWS,
    GCP, Azure, DO, OVH, Scaleway…
    ➔ Battery included, but complex
    Kubernetes

    View Slide

  34. ➔ The Kubernetes package manager
    ➔ Like apt but, for Kubernetes
    ➔ Charts: packages for Kubernetes
    ➔ Graphical tools (Lens IDE, Ahoy)
    ➔ Templates for Kubernetes YAML
    manifests
    Helm

    View Slide

  35. Symfony & Kubernetes
    ➔ Images provided by Symfony Docker are compatible
    with Kubernetes
    ➔ Images provided by API Platform are compatible too
    ➔ API Platform provides a ready-made Helm chart that
    you can use with Symfony Docker too!
    ➔ Just copy it and run helm install
    @dunglas

    View Slide

  36. ➔ Any questions?
    Thank you!

    View Slide