Skip to content

Instantly share code, notes, and snippets.

@uluumbch
Last active March 19, 2025 06:50
Show Gist options
  • Save uluumbch/327f4403f53f8b6d4dd7a38039ec243a to your computer and use it in GitHub Desktop.
Save uluumbch/327f4403f53f8b6d4dd7a38039ec243a to your computer and use it in GitHub Desktop.
Create a laravel project via docker using laravel installer

Usage

copy and paste the script. Make sure docker is running

You can change the 84 to another version of php, for exampe 82 for php 8.2, etc

#!/bin/bash
APP_NAME="my-laravel-app" # Change this to your desired project name
docker info > /dev/null 2>&1
# Ensure that Docker is running...
if [ $? -ne 0 ]; then
echo "Docker is not running."
exit 1
fi
docker run --rm --interactive --tty \
--pull=always \
-v "$(pwd)":/opt \
-w /opt \
-e APP_NAME="$APP_NAME" \
laravelsail/php84-composer:latest \
bash -c "laravel new \$APP_NAME --no-interaction && cd \$APP_NAME && php ./artisan sail:install --with=mysql,redis,meilisearch,mailpit,selenium"
if [ -d "$APP_NAME" ]; then
cd "$APP_NAME"
else
echo "Laravel installation failed. Check the logs above."
exit 1
fi
CYAN='\033[0;36m'
LIGHT_CYAN='\033[1;36m'
BOLD='\033[1m'
NC='\033[0m'
echo ""
if command -v doas &>/dev/null; then
SUDO="doas"
elif command -v sudo &>/dev/null; then
SUDO="sudo"
else
echo "Neither sudo nor doas is available. Exiting."
exit 1
fi
if $SUDO -n true 2>/dev/null; then
$SUDO chown -R $USER: .
echo -e "${BOLD}Get started with:${NC} cd $APP_NAME && ./vendor/bin/sail up"
else
echo -e "${BOLD}Please provide your password so we can make some final adjustments to your application's permissions.${NC}"
echo ""
$SUDO chown -R $USER: .
echo ""
echo -e "${BOLD}Thank you! We hope you build something incredible. Dive in with:${NC} cd $APP_NAME && ./vendor/bin/sail up"
fi
docker run --rm --interactive --tty \
--pull=always \
-v "$(pwd)":/opt \
-w /opt \
laravelsail/php84-composer:latest \
bash -c "laravel new example-app"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment