Connecting a Symfony app to the DB using Docker — Mac Users with OrbStack

Alice Wanjiku
2 min readJan 12, 2024

--

Creating a little (beginner-friendly) cheat sheet that I can reference quickly when doing quick refreshers. Meanwhile, I will share it with you so you can have an easy time too. Happy Hacking!

  • you need to run “composer require symfony/orm-pack
    $ composer require --dev symfony/maker-bundle
    ” first if your project is a “skeleton” or a microservice or an API. (Tip: iterm allows you to paste and run both commands.)
  • The next step is to make sure that OrbStack is running.
  • Set up your docker-compose file. It needs to have an image (from docker hub).
    - Add environment configurations (username, password, DB name)
    - define volumes. This helps you make sure that your data is not lost when you shut down the container. Docker is ephemeral!
    -(I am using Maria DB for no good reason :), well it gives you a bit more flexibility and features compared to MySQL. You can find the ultimate comparison on this URL.)
    Finally, Here is a screenshot of my docker-compose file.
  • run “docker-compose up” — this will pull the image from the hub. You can run “docker-compose up -d” if you want it to run in the background.
  • setup config/packages/doctrine.yml to specify your server version
  • Setup your.env file to reflect DB passwords, name, and other configurations as outlined in Symfony documentation.

--

--

Alice Wanjiku

Software developer — Symfony, Laravel, Node Js and React Js, Vue Js