sudo ./vendor/bin/sail artisan migrate
sudo ./vendor/bin/sail root-shell
In addition, Dockerization brings significant benefits in terms of isolation, scalability, and resource efficiency for Laravel projects. Each Docker container runs in its own isolated userspace, preventing conflicts between different applications or microservices running on the same host. It also enhances security by limiting the potential blast radius of vulnerabilities.Deploying your Laravel application with Docker on a VPS might seem daunting at first – especially when you’re juggling server configurations, dependency management, and ensuring your app runs seamlessly in production. Even after building a well-optimized web application, replicating your local environment on a server can be a whole new challenge.Sail simplifies the process by handling the Docker setup for you, making it a great option whether you’re new to Docker or looking for a streamlined approach.
Table of Contents
- 1 Why Use Docker for Laravel Deployment?
- 1.1 Advantages of Dockerizing Laravel Applications
- 1.2 Step 1: Download Your Laravel Application
- 1.3 Step 2: Navigate into Your Application Directory
- 1.4 Step 3: Start the Docker Containers with Laravel Sail
- 1.5 Step 5: Run Database Migrations
- 1.6 Step 6: Access Your Application
- 1.7 Step 7: Troubleshooting Potential Permission Errors (If Needed)
- 2 Wrapping Up: Deploying Laravel with Docker on a VPS
- 3 FAQs on Deploying Laravel with Docker on a VPS
- 3.1 What are the benefits of using Docker for Laravel deployment?
- 3.2 How do I secure my Dockerized Laravel application?
- 3.3 Can I use Docker Compose with Laravel?
- 3.4 What is the best way to manage environment variables in Docker?
- 3.5 Is Docker necessary for deploying Laravel?
- 3.6 What are the alternatives to Docker for deploying Laravel?
- 3.7 Can I use Kubernetes to manage Laravel deployments?
Why Use Docker for Laravel Deployment?
Ready to experience truly effortless server management and application deployment?Once the previous command completes, navigate into the newly created project directory. Remember to use the actual application name you chose:While Sail simplifies the Docker aspect for a single Laravel project, managing the underlying server, handling security configurations, setting up monitoring, deploying multiple applications, and keeping everything updated still requires significant effort and Linux expertise. This is where platforms specifically designed for server management truly shine.RunCloud works with standard Laravel applications, high-performance setups such as Laravel Octane, and popular CMS platforms such as WordPress. You can start using RunCloud and choose from various optimized server stacks directly through the RunCloud interface.
Advantages of Dockerizing Laravel Applications
Absolutely, Docker Compose is highly recommended, especially for local development and simpler multi-container production setups with Laravel. It allows you to define and manage all the related services your application needs (such as the web server, PHP-FPM, database, and cache) in a single YAML file. This makes it easy to spin up, connect, and manage the entire application stack with simple commands.Enter the main application container as root:The primary advantage of containerizing your Laravel applications with Docker is that it allows you to have a consistent development and deployment experience for all developers. By packaging your application code along with the exact versions of PHP, extensions, web server (Nginx/Apache), system libraries, and other dependencies within a Docker image, you eliminate variations between developer machines, testing environments, and production servers.You can secure your Dockerized Laravel app by following standard web security practices within your code, using minimal, trusted base images, and running containers as non-root users. RunCloud provides several security features out of the box and simplifies configuration management.Deploying a Laravel application from your local development setup to a live production server is not easy. If you have deployed applications in the past, you’ll probably agree that the deployment process introduces numerous complexities, and it’s challenging to manage environment consistency.sudo ./vendor/bin/sail up -d
This section explains how to deploy your Laravel application on a generic cloud VPS using Docker.cd runcloud-tutorial
📖 Suggested read: Understanding Docker Services | RunCloud Docs
- Server Access: You’ll need access to a Linux server (such as a VPS from providers such as DigitalOcean, Linode, Vultr, etc.) via SSH.

- Sudo Privileges: You must be logged in as a user with sudo privileges or as the root user directly (though using a sudo user is generally recommended for security). Remember, commands run with sudo have elevated permissions, so execute them carefully.
- Docker Installation and Service: Docker must be installed and running on your server. You can check if it is installed by running docker –version. If it’s not found, you’ll need to install it following the official Docker documentation for your Linux distribution.
If you are using RunCloud to manage your servers, then you can refer to our Laravel documentation to learn how to do this effectively.

📖 Suggested read: What Are Docker Images And How To Use Them
Step 1: Download Your Laravel Application
📖 Suggested read: How to Use Cloudflare Firewall Rules to Protect Your Web Application Before we begin installing Laravel, ensure your server environment is correctly prepared.Change ownership recursively: This command changes the owner and group of the html directory (as well as everything inside it) to sail:

Docker fundamentally solves this by enabling you to package your entire application into standardized, isolated units called Docker containers, including its specific dependencies and configurations.For security reasons, avoid hardcoding environment variables or committing .env files directly into your Docker image. Instead, pass environment variables into the container at runtime using Docker’s -e flag, Docker Compose environment, or env_file directives.
curl -s
: Downloads the script silently (no progress meter).https://laravel.build/runcloud-tutorial
: This tells the service to generate a setup script for an app named runcloud-tutorial.| sudo bash
: Pipes the downloaded script directly to the bash interpreter, executed with sudo (root) privileges. This creates the project directory and sets initial permissions.
If you cannot access the site via the server’s IP address, your server’s firewall might be blocking incoming connections on port 80 (HTTP). You will need to configure your firewall (e.g., ufw, firewalld, or your cloud provider’s firewall settings) to allow traffic on TCP port 80. We will use the official Laravel.build service to download a starter Laravel project configured for Sail. The command below downloads a script and executes it using bash.RunCloud makes it incredibly easy to develop, deploy, and maintain your web applications across one or many servers, all from a single, intuitive central dashboard.
Step 3: Start the Docker Containers with Laravel Sail
Compared to traditional virtual machines, containers have significantly lower overhead as they share the host OS kernel. This leads to faster startup times, better resource utilization, and the ability to run more application instances on the same hardware, ultimately improving overall reliability and cost-effectiveness.Yes, Kubernetes (K8s) is a powerful container orchestration system suitable for managing complex, large-scale Laravel applications requiring high availability, auto-scaling, and rolling updates. However, it introduces significant operational complexity compared to simpler Docker or Docker Compose setups. Managing deployments via a tool such as RunCloud provides sufficient capability for many projects without the K8s learning curve.Once the containers (including the database container) are running, you’ll need to set up your application’s database schema. Laravel uses “migrations” for this.
sudo
: We use sudo here because Sail needs root permissions to manage Docker networking and volumes../vendor/bin/sail
: Executes the Sail script located in your project’s vendor directory.up
: This command tells Docker (via Sail and Docker Compose) to create and start the containers defined in the docker-compose.yml file. The first time you run this, it will download the necessary Docker images (such as PHP, Nginx, MySQL), which can take several minutes (sometimes ten or more), depending on your internet connection.-d
: Runs the containers in the background so your terminal prompt remains available.
Sometimes you might encounter file permission errors within your Laravel application, due to how Docker handles file volumes and user mapping between the host server and the container. This often happens because the web server process inside the container (running as the sail user) doesn’t have write permission to files owned by the root user on the host (created during the initial curl | sudo bash step).
Step 5: Run Database Migrations
Note: Many cloud providers offer server images with Docker pre-installed. Using one of these can save you the installation step.This process is not only time-consuming but also prone to errors and inconsistencies. Subtle differences between development, staging, and production environments cause unexpected bugs and failures during application deployment.If you suspect permission issues, you can fix them by changing the ownership of the project files inside the container to the sail user.
sudo ./vendor/bin/sail
: Again, we use Sail to execute a command.artisan migrate
: This tells Sail to run the PHP artisan migrate command inside the main application container (the one running PHP). This command creates the necessary tables in the database (like the users table, etc.).
Your Laravel application should now be running and accessible!

Step 6: Access Your Application
exit
curl -s https://laravel.build/runcloud-tutorial | sudo bash
This isolation makes it easier to scale specific components of your application (e.g., PHP-FPM workers, queue workers) independently based on demand, often orchestrated via Docker Compose or more advanced container management tools such as Kubernetes.
Step 7: Troubleshooting Potential Permission Errors (If Needed)
Sign up for RunCloud today and see the difference for yourself!Close the container shell:Laravel Sail is an interface for managing your application’s Docker containers. We’ll use it to build and start the necessary services (web server, PHP, database, etc.).Run this command, making sure you replace runcloud-laravel-app with the desired name for your application’s directory. This name will be used for the project folder.

You can deploy your web applications using the traditional deployment directly onto a configured VPS. RunCloud makes this process extremely easy by providing a centralized dashboard for VPS management.Let’s dive in!
- chown: Change owner command.
- -R: Recursive (apply to the directory and all files/directories within it).
- sail:sail: Set the user to sail and the group to sail.
- html: The target directory (which corresponds to your project root, mounted at /var/www/html).
Run the following command to execute the default Laravel migrations:Execute the following command to start Sail in “detached” mode (-d), meaning the containers will run in the background:

Wrapping Up: Deploying Laravel with Docker on a VPS
Traditionally, server setup involved manually installing and configuring PHP, web servers such as Nginx or Apache, databases, caching services such as Redis or Memcached, and countless system libraries – all directly onto the server’s operating system.In this comprehensive guide, we’ll show you how to deploy Laravel with Docker on a VPS using Laravel Sail.This portability means a container built on one machine will run identically on any other machine with Docker installed, drastically reducing bugs related to environment differences. 📖 Suggested read: Docker Security: Best Practices to Secure a Docker ContainerYou’ll learn how to download Laravel, spin up essential services such as the web server, PHP, and database, and run the necessary setup commands to get your application live.📖 Suggested read: What is Docker And How Does it Work
FAQs on Deploying Laravel with Docker on a VPS
What are the benefits of using Docker for Laravel deployment?
How do I secure my Dockerized Laravel application?
Can I use Docker Compose with Laravel?
What is the best way to manage environment variables in Docker?
Is Docker necessary for deploying Laravel?
What are the alternatives to Docker for deploying Laravel?
Can I use Kubernetes to manage Laravel deployments?
chown -R sail:sail /var/www/html
You should see an output indicating that the migrations ran successfully.