Setting Up Docker and Laravel Sail on Ubuntu
Sunday, September 22, 2024
// 1 min read
Table of Contents
This guide aims to assist you in setting up to set up Docker and Sail for Laravel local development environment on Ubuntu.
Install Docker
The first thing to do is to add the official Docker GPG key to your Ubuntu system so that you can install Docker from its official repository:
install -m 0755 -d /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.ascsudo chmod a+r /etc/apt/keyrings/docker.ascThen you can add the official Docker repository:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/nullFinally, you can install the Docker package:
sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginAdd your user to the Docker group
In order to be able to use Docker without sudo you can add your user to the Docker group.
sudo usermod -aG docker $USERFor the group change to take effect, you'll need to log out and log back in, or you can run the following command to apply the group change without logging out:
newgrp dockerTesting the installation
Once Docker is installed, you can verify the installation by issuing the command:
docker versionYou should see something like this:

After check if you can run a Docker command by pulling down the hello-world image:
docker pull hello-world
Create Laravel Project
Create your new Laravel application:
curl -s https://laravel.build/my-app | bashThen navigate to the new application directory and start Laravel Sail:
cd my-app
./vendor/bin/sail up
I recommend creating a shell alias, so you do not need to type vendor/bin/sail all the time.
alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'Also, you can use the detached mode (-d), so the container runs in the background, and you can keep using your terminal window. Now you can just run the following command:
sail up -dTo stop the container run:
sail downOnce the application's Docker containers have started, you should run your application's database migrations:
sail artisan migrateNow, you can visit http://localhost:8000 in your browser to see your app is up and running.

If you want to support my work, you can donate using the button below. Thank you!