How to deploy Docker Applications with Laravel Forge

Search for a command to run...

Muito bom o post. Quando vc instala Traefic não precisa configurar nada no cloudflare para apontar para esse sub domain? E pelo que entendi não vou precisar configurar ngnix tambem, nem para esse host e nem para os futuros containers(apps) com docker, correto?
Obrigado Elinardo.
Pensa no Traefik como o "roteador". Dependendo da configuração, que tem em conta o hostname, encaminha pedidos para o serviço (container) correspondente.
O container de Laravel vai ter que ter Nginx e FPM ou outro webserver.
Se queres colocar Cloudflare com IP anonimizado, então terás de configurar o Certificado Origin. Da forma que está, é o Traefik que coloca SSL com Lets Encrypt.
Há muita forma de fazer este setup. O que te recomendo é experimentar várias, para que possas tirar conclusões do que é melhor para o teu caso de uso.
Patricio Muito exclarecedor! Obg. Deste que me deparei com seu post q venho estudando a possibilidade de containizar todos os meus prontos Laravel com vue. Pq mesmo com laravelForge que ajuda muito no setup, sempre dar trabalho. Localmente eu já uso laradock. Eu vou subir uma nova vps e ver se eu consigo fazer uma mistura de laradock com Traefik. Já vi uns posts sobre. Tai até uma ideia de vcs escrever algo sobre isso se n for pedir muito. Rsr Muito bom seus posts cara. Obg. Abraços do Brasil.
Elinardo Silva Ora essa, muito gosto em conseguir ajudar.
Verifica esse projeto também https://github.com/serversideup/spin
As imagens base de Docker são espetaculares, o autor dá sempre mt feedback, e lançou recente esse Spin, que é como o Sail, mas para Dev e Prod
Um abraço
Patricio Valeu Patrício. Obrigado. Estarei verificando elas. Abraço
Very good article, especially for people making a first foray into the world of setting up Docker in Laravel Forge. I wish there were more basic articles for this kind of thing, for as always seems to be the case, there's no "middle ground", you either find articles that are way too basic and no virtually nothing, then there's a big leap towards "computer science" level where the article is just way too complex for "normal people" to follow along with...
Excellent tutorial - thanks so much! I've just set up my first Forge server with docker, and it's running fine.
Fun fact, while deep diving how Claude Code works, I realised some files were stored with a .jsonl format! What’s this, a typo?? 😀 Of course not…. It's a text format where each LINE is a valid JSON object. So why this and not just a JSON array?! Reg...

This apply the dependencies transformations needed, and add the PostCSS config file needed. npm remove @tailwindcss/vite npm remove tailwindcss npm install tailwindcss@3 @tailwindcss/forms npm install postcss autoprefixer cat > postcss.config.js ...

Warning: I just deprecated it. Claude Code is fantastic, it does the same job I wanted to achieve with this. It’s a CLI instead of an UI, but it does 10x or 100x more than the current application situation. Get it here: https://docs.anthropic.com/en/...

I know, Livewire and Tailwind are the base for Filament, and this tutorial is not any hidden gem, but my gut feeling tells me I should write it. It shows few steps of the docs, but many don't get there, and don't even know this is possible. Filament ...

You're reading this, so you want the Login page ready to go in local environments, without having to type in a default user (configured in your seeder). Let's go. Let's create a Filament Page. Press <enter> for an empty answer, when asked if the page...

Most likely, if you’re reading this, you are a Laravel Forge user. Probably, also a Docker user or with interest in it. I was a happy Forge user for a long time in a row until I started using Docker, learned a bunch of its advantages, and ultimately fell in love with such.
Why use Docker for development and deployments, you may ask? I have a bunch of good reasons I could share, but that will be in another post.
First things first, let's provision a server.

The relevant thing to learn here is to choose a Worker Server. This is because we want the server as clean as possible and ports 80 and 443 available for web hosting. All other VPS options can be sized per your needs.

So, in a matter of minutes, we have our newly provisioned server! We also know its IP address, so it's time to make the DNS records and point the desired domains to such IP address.

I ended up doing this demo for the blog post with forge-docker-app.jpat.dev and forge-docker-traefik.jpat.dev, and we will see why in a minute.
So now we need Docker installed in our VPS. We can accomplish this very easily by adding a Recipe. Lets do just that and run it in our VPS.
Copy source code from here


By now, we can see the recipe log, or SSH into our server and check Docker and Docker Compose are installed! 🚀

So now we are going to install a "web server", which is Traefik. It's not exactly a webserver; think of this like a Router in your Laravel application. It will take care of the server ports 80 and 443, handle SSL with Let's Encrypt automatically, and point the requests to the right Docker application.

In the simple diagram, we can see a VPS running four containers: Traefik and three containerized apps. For this example, they would be all accessible from the outside, redirecting to SSL if needed and routing the request depending on the required host. It's a very simplified version and much more can happen. Let's keep it like this for simplicity's sake!
We can use this repository ijpatricio/traefik-for-forge as is; it's meant to be used by this "common use-case", but of course, feel free to fork, use and customize.

In Forge, inside our server, we go to create a new site, Traefik.

Now we install the repository and leave "Install Composer Dependencies" unchecked.

We now have a freshly installed repo! Now let's do some preparations. We can SSH into the machine and run the commands in the site's directory or run right from the Commands in the Forge UI. I absolutely recommend SSH into the machine and running it from there.
docker network ls | grep web || docker network create web
cd ~/traefik
cp .env.example .env
cp docker-compose.prod.yml docker-compose.yml
# Choose a username and a strong password
./Taskfile auth username password
Let's now fill the environment variables in the Forge UI. Example below.

We also need to change the deploy script to:
cd /home/forge/traefik
git pull origin $FORGE_SITE_BRANCH
cp docker-compose.prod.yml docker-compose.yml
docker-compose up -d --remove-orphans

It should now look something like the above. We can press Deploy now.


With any luck, deploy must be complete now, and the deploy log will look something like the above, and a docker ps on the machine will show the running container, and mapped ports :)
Furthermore, we can visit https://forge-docker-traefik.jpat.dev/ and check that is password protected.

After entering credentials, we have our SSL secured Traefik dashboard.

Woohooo!! Glad you made it so far! By now, we can already deploy applications just by using a docker-compose.yml file!
From here, we can use public images or adds login(s) to use with private registries.
Here, continue the journey on How to Dockerize a Laravel App to run in Laravel Forge.
Happy coding, happy deploys!!
Patricio