How to build and deploy Laravel project with Docker

Image for post
Image for post

Hi everyone. In this post, I will tell you how to build and deploy to server your Laravel project with docker.

Firstly I want to write about Laravel deployer. Laravel deployer is a package for using to deploy Laravel project to server. This package has many futures. Deployer must create your code versions and you can be back to the previous version. I share thelist of futures.

  • Simple setup process
  • Zero downtime deployments
  • Ready-to-use tasks for Laravel
  • Choose your deployment strategy
  • Agentless, it’s just SSH
  • Did something go wrong? Rollback to the previous release
  1. Firstly you must install a package with the composer.
composer require lorisleiva/laravel-deployer

In order to generate your deployment configuration file, simply run:

php artisan deploy
  • It will ask you a few questions to help you get started and generate a config/deploy.php file.
  • Read more about the available options, tasks, strategies; how to customize your hosts, your deployment flow, and much more in the documentation.

When you’re ready to deploy, run:

php artisan deploy
  • If anything goes wrong during the deployment flow, the release will be discarded just like nothing happened.
  • Because we are using zero-downtime deployments, make sure your server’s root path points to the {{deploy_path}}/current symlink.
  • If your project has already been deployed, before using Laravel Deployer, you might be interested in this first deployment strategy.

Laravel deployer has a some commands.

deploy                # Deploy your application
deploy:configs # Print host configuration
deploy:current # Show current paths
deploy:dump <task> # Display the task-tree for a given task
deploy:hosts # Print all hosts
deploy:init # Generate a deploy.php configuration file
deploy:list # Lists available tasks
deploy:rollback # Rollback to previous release
deploy:run <task> # Execute a given task on your hosts
logs # Dump the remote logs of your application
ssh # Connect to host through ssh

if you have multiple hosts you can run deployment like that.

php artisan deploy -s upload

or you want to deploy a development server. You can run this

php artisan deploy -s upload

To use these commands you configure your deploy.php file like that.

'hosts' => [
'' => [
'deploy_path' => '/var/www/',
'user' => 'deployer',
'' => [
'deploy_path' => '/var/www/html/',
'user' => 'deployer',

In deploy.php you can configure hooks like deployment start or end build and others. This helps you do something at every stage.

You find Laravel deployer’s official documentation in there. Check it for many things.

If this article is helpful for you to follow me for new useful information. Thank You!

I am iron man

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store