Running multiple Laravel apps locally with Docker
HTML-код
- Опубликовано: 3 окт 2024
- Want to learn more about how to develop and deploy Laravel applications with Docker? I've released a premium course featuring 23 videos for just $29! Check it out here: laraveldocker.com
In this 13 minute video, I'll show you how to run two separate Laravel applications using local Docker networks and communicate between them.
Join my weekly newsletter for tips on Laravel + more: aschmelyun.sub...
Here's the repo for the docker-compose-laravel project mentioned in this video: github.com/asc...
You'll learn how to:
Configure docker-compose files for each app
View each separate Laravel application in the browser
Create a shareable bridge network in Docker
Make an API call between apps using a Docker service hostname
Follow me on Twitter! / aschmelyun
Thanks Patreon supporters!
Sam Ross
PK
Melissa Kipp
Directly support these videos @ / aschmelyun
I am starting to transition to docker env and these videos are gold
That's true. Those videos are a big help. Maybe @Andrew Schmelyun can give example for mount volume in the host machine and it permission
Great tutorial.
With docker compose version 3.5 you can set network name. So you don't need to checl for it in app-two:
networks:
laravel:
app-shared:
driver: bridge
name: app-shared
Nice! Thanks for the tip!
Your videos are helping me tremendously. Thank you so much for doing these. Hopefully you gain more subscribers since your videos are well made, easily understood and of high quality. More powers to you!
man this quick run is such a relief for the brain
Very helpful video! That would be great if you could show how to deploy multiple (laravel) apps in a VPS using docker containers!
just discovered your channel and I really enjoy your videos. Can't wait for you to discover traefik, I assumed this would be the subject of this video (I personnaly use it to run multiples stacks on my dev laptops) ! But hey, still some awesomeness for you to discover !
One juste little tiny thing that bothers me every time , your syntax for routes, i find [Mycontroller::class, 'action'] instead of 'Mycontroller@action' soooo much more practical since I can ctrl-click the name of the controller ! ;)
On a more important note, I would probably adress the very common issue of users difference between the host and the container, I've noted a comment related to this under this video.
i for one add two arguments to the build section of my docker-compose :
args:
user: laurent
uid: 1000
That I use in the Dockerfile
FROM php:8-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
.... blah blah blah install some cool stuff ...
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN chown -R $user:$user /home/$user
WORKDIR /var/www
USER $user
This way both users in the host and the container share the same name and the same id, preventing permissions errors for files created inside the container (like logs or cache files) with the default root user's id 1.
And again... Another video on point... Thank you
Great video and thank you. I will be trying this out.
Love your content. Keep it up man.
Thanks for the help
awesome. i was looking for it.
Awesome ! Could you show us how to forward to some domain?
Thanks sir. This was a very good example on running microservices. Hopefully you can also add the tutorial for adding the domain. Also, is it possible to only access the second docker with only one authentication from the other one? Thank you :)
It worked , thanks so mutch .
Can i have the running success code ?
I stuck in the cURL error 7 like forever
Can you continue this tutorial with deploying these two apps on production with Letsencrypt and domains /subdomain for the api and web app? Plz!!!!
I would also like to see a deployment video tutorial
@@yuniorespinal9926 I would also like to see a deployment video
Great! Thanks for the tutorial
Why the connection to mysql you just need to use the service name but not the connection between two laravel app?
Is it because they resides in different docker-compose file?
Very helpful video, cheers
Thanks! Great video
This is really helpfull, thank you so much!
Important note
You must also edit default nginx conf. At the line "fastcgi_pass php:9000;" you must substitute "php" with your php-fpm sevice name, otherwise nginx will not work properly.
how to do that
Thanks, it saved a lot of time, it's actually the container name not the service name. can you please explain why this error is happening
thanks, it helps me alot )
This is really helpfull, thank you so much!
but my question is: should I share some containers like npm when multiple apps? and if I have 5 apps, I must build and run 5 group of all nginx/mysql/npm/composer/and any other containers that might run out of my server resources
Can i use this docker compose config in production ?
Nice videos!! I hope you could do one for ssh access directly! Thank you man!
Thanks ! can you please make tutorial how to make : Laravel JWT Auth API with Socialite, How to make Realtime API with Laravel !
thanks
It seems the laravel app running inside docker is slow (at 12:33). How to address that issue?
I am using wsl2 ubuntu and I get this error. Any idea why?
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
the same. did you solve problem ?
Hey Andrew, Thanks for making this tutorial. It helps me a lot.
I'm running Laravel and WordPress following your process. But in the WordPress system, sometimes I get "File not found" on the browser page reload.
Can you please help me with that?
I assume there is also a way to spin up only one nginx proxy container
docker network ls to list the networks
Great vidoes, it would be so lovely, If you show us how to use reverse proxy with these configs, in order to map server_names to ports
I'll add that video idea to my list!
Hi is this the way to create microservices?
quality content
Why my container is so slow when load page, over 4 -> 5s , i tested with project laravel 8.x default. Please help me! Thank you so much
Can you create a video on how to use nuxtjs with laradock?
When using App_2 as the API for App_1 does it need to go through the web.php route? Could that that take place instead in the api.php?
Hi Andrew ,
How do you create and install a self-signed wildcard cert for browser with cert.sh ?
hi andrew just i want to know how i can get the full premium cours of laravel and docker i am new member
hey let say i have a container running at nginx port 80:80 and 127.0.0.1 for dev.example.test. how do i run another project say for dev.hello.test?
how can we use traefik in this same setup to eliminate the port in urls for poper working with cookies and other stuff same like in production.
You can set Traefik up so that it acts as a proxy for your container network. You can set a Host that routes to a specific container, without the need for ports. So you can have two containers, with your-domain.com pointing to Container A, and api.your-domain.com pointing to Container B without any exposed ports on either (besides :80 and :443).
The Traefik docs are a pretty good place to get started!
Awesome =))))
hi, is it possible to instead of using localhost to use the name of your domain
I can do that on ubuntu in etc/hosts
but in mac?
Can you please share how your development environment. Like fonts, themes, etc. Until today, I feel my current development environment is good but I don't feel content.
I just built a page for this on my website! Check out aschmelyun.com/uses it has everything I use on there.
How do we use bash for second MySQL service
Thanks, I am going to ignore docker completely, I see no use for it
Great video, would this still work if you set up a local host name for both eg: siteone.test and sitetwo.test using say the macOS host file?
Unless you're routing them through the same Laravel app using domain routing, unfortunately no. You can use two different domains, but you would also need a different port. E.g. siteone.test and sitetwo.test:81
why laravel is slow on MacOs????
It's not Laravel, it's Docker. Unlike on Linux servers and computers, there's a virtualization layer between the MacOS filesystem and Docker's filesystem, which causes a pretty significant delay.
I have a confusion,
If I want to make a dockerized project then I will not install php or laravel im my local machine. I will install everything within docker. But If I want to use php artisan command to create laravel controller, middlewares or laravel tinker features, then what will I do ? It's not possible I will create everything directly in docker container using command line. I need an editor to modify those files.. Then what will I do?
It'll be helpful if anyone give response. Thank you!
You should use a volume mount to sync your local directory into the running docker container (you can use the -v option for this).
Then, run the commands in the Docker container by using `docker exec -it container-id php artisan make:controller` and it'll show up in both the container and your local file system!
@@aschmelyun Okay. Thank you
You don’t need another network inside the docker containers, you can access the other container’s services by using the ip-number of your host computer. Let’s say the ip of host computer is 192.168.1.100, then you can use in app-one’s UserController: $response = Http::get(‘192.168.1.100:8081/users’);
The behaviour of this approach is not predictable. From Connection Time Out errors to Nginx gateway time out errors.
good videos on the subject but im having a hard time moving from homestead/vagrant, dockers seems like too much work
And now make this tutorial for Windows! Ahahah
good info but still, homestead/vagrant seems a better solution for me
Instead of 2 docker compose, you can use One docker compose file to run multiple Laravel.
Just 2 php sections, 1 MySQL section and 1 Phpmyadmin section. That's it. One Compose file can run 10+ Laravels.