Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kvalbot's avatar

Laravel deployment with a Docker environment question

I am learning Docker and I find it amazing, but I am having some issues understanding something that should be simple. I would be very helpful if someone reads this wall of text and give me some guidance.

I am using PHP with Laravel. I setup my local environment using a couple of containers with docker-compose. Everything's working fine so far.

I would now like to setup an automated (or semi-automated) deployment process to my DigitalOcean droplet. Before Docker, I had a custom written script, which was pulling the latest version of the code from GitLab, executing composer install, all necessary artisan commands and creating the new release, while keeping the old one (pretty standard). However, I am struggling with reproducing something similar with Docker. I can't really just pull the latest changes and run composer, because there's no composer on the host machine, only in the container. Same for the artisan commands, migrations etc.

Just some context: I am using nginx:alpine, mysql:5.7 and a custom image (defined in the Dockerfile) which installs all necessary dependencies - composer, nodejs, curl etc. copies the project in the container and running composer install. At which point and how can I run the artisan commands - migrations, cache clearing etc.? Do I need to run them manually with docker-compose exec? What are some best practices on deploying a simple Laravel project in containerized environment? I've been googling for a couple of days, but I am just getting more and more confused. I even read a Medium article which suggested to have a docker-compose for local env and for production, which I think defeats the purpose of reusability.

I would be more than happy to share the code I have so far, I just didn't want this post to explode even more.

0 likes
0 replies

Please or to participate in this conversation.