r/PHPhelp • • Nov 20 '21

Should I use Docker?

I'm a PHP (mostly laravel) developer. I currently use laragon as my dev env. I love to move to docker, because to try and learn it. But building dockerfile and for each project is a pain in the ass. Is there any other dev friendly way to create dockerfile? Or should I continue using laragon? (I heard about Laravel Sail, But some of my projects are not fully laravel)

10 Upvotes

17 comments sorted by

5

u/chocolombia Nov 20 '21

Hi there, when I first started with docker I used to have tons of issues, specially understanding the logic behind it and as you say, setting up dockerfiles, entry points, compose, etc etc, was a headache, nowdays it's my #1 en tool, starting from the fact that changing something is crazy easy, to the fact that everything is standard from dev to prod, nowdays my life is way easier, and handling the whole dev cicle has never being this easy.

Edit: look for the standard images, I work with the official php, plus some twiks that I need for the CMS I use, and work has never being easy

1

u/SeriouslyYoutube Nov 20 '21

Do you use any tools or something? or do it from scratch?

3

u/chocolombia Nov 20 '21

Nowdays I use the official php image, install libs on the dockerfile and environment initialization on entry points, but as someone pointed, at first it's good to start from scratch, and learn your way, the important thing is to understand the base concepts, and basic things like docker being stateless, and that is should only run a single process, bit think of it as a Linux process where you can run stuff like apache or databases, also volumes are a really important part since that's how you persist stuff on docker. Have you tried the official images? https://hub.docker.com/_/php also, how are you setting up your environment? (Windows or Mac or Linux) lol, I really love docker so if I can provide any help just ping

2

u/SeriouslyYoutube Nov 20 '21

I'm on Windows. I have tried using a larvel image on docker. But its very confusing to understand and customize.

2

u/chocolombia Nov 20 '21

Ok, first things first, most images are designed to work under Linux, so it would work better using wsl2, here you can find a guide https://www.pimwiddershoven.nl/entry/lightning-speed-development-on-windows-10-with-wsl-2-docker-terminal-and-jetbrains-intellij-pycharm-phpstorm about the dockerfiles, think of the as commands you run on a Linux in the initialization process, every RUN is a step on the setup where you run whatever command you need, also this link has some good information on setting up a Laravel image https://www.digitalocean.com/community/tutorials/how-to-install-and-set-up-laravel-with-docker-compose-on-ubuntu-20-04 and f you want share the image you're working with and which question do you have, but mainly, it's the image itself working? And how are you running the db part, are you using docker-compose yet?

4

u/slowlycatchiemonkey Nov 20 '21

Create from scratch first, learn the basics

2

u/compsciscrub Nov 21 '21

Lando is built on top of docker compose. I use it for pretty much everything PHP. They have “recipes” for certain configs that shorten the setup process.

2

u/SeriouslyYoutube Nov 22 '21

I'm going with that, some one recommended it early in the post.

4

u/CptIceberg Nov 20 '21

You should try Ddev, its a wonderfull tool which allow you to benefit from a fully containerized env without having to setting it up yourself ! It adapts automatically to the project too (Laravel, Symfony, Drupal, Wordpress). Its absurdly easy and powerfull

4

u/vimsee Nov 21 '21

I always recommend techworld with nana. She explains things very good.

2

u/SimpleMinded001 Nov 21 '21

I'm also a fan of her videos. She explains everything so well! Can't recommend enough.

2

u/biinjo Nov 21 '21

Pro tip; go to Udemy.com and get yourself a docker course from Bret Fisher. He’s the best teacher. It took me about 7 days to get from nothing to a solid production environment.

Bonus; a lot of courses are just $10 now due to Black Friday.

In addition, serversforhackers.com has a great course about setting up Laravel + Docker dev and production environments as well. Slightly more expensive than $10 but worth every penny since Chris shares some very useful bash scripts I still use today.

2

u/SiegFuse Nov 21 '21

Not long ago i have prepared some small docker configuration for myself - https://github.com/Fresh-Advance/development. You can try it out too, and improve if something is missing for your special case.

If you need backend only stuff, remove unneeded containers from docker-compose which you get after `make up` command. Check the readme.

Sadly there are no php8 right now, but i am planning to add that container variant as well soon.

1

u/Sensitive_Pianist_92 Nov 21 '21

Tou can read about laravel sail - it uses docker, the whole installation takes a few minutes.

Besides that, you can read how to usedocker and set up all the env on DigitalOcean site

1

u/benelori Nov 21 '21

After you learn the basics you will realize that you can reuse the same docker file across projects

0

u/AnnualPanda Nov 21 '21

If what you're doing is working for you there is no reason to change it.

People are sometimes adopting technology that is beneficial for specific use cases and then random people start thinking they need to know/use it too because it is a new buzzword.

Don't be one of those people. Make analytical decisions about what is best for what you're doing

Note: it's good to have a general understanding about new tech, but it doesn't mean you have to use it if it's not appropriate

2

u/SeriouslyYoutube Nov 21 '21

The problem is, The current company I'm working on doesn't use Docker, So I'm safe. But I'm planning to move to a better company. All of the good ones use Docker. So I need to learn. Before I move.