DEV Community

엽토군
엽토군

Posted on

Start a new Laravel 12 project with Docker only

1. Build a simple image.

This is in order to skip this step. This manual premises that you want everything containerized.

FROM php:8.4
COPY --from=composer /usr/bin/composer /usr/bin/composer
COPY --from=node:slim /usr/local/bin /usr/local/bin
COPY --from=node:slim /usr/local/lib/node_modules /usr/local/lib/node_modules
ENV PATH="/root/.composer/vendor/bin:$PATH"
RUN apt-get update -y && \
    apt-get upgrade -y && \
    apt-get install zip unzip git -y && \
    composer global require laravel/installer
Enter fullscreen mode Exit fullscreen mode
docker build -t laravel-installer:12 .
Enter fullscreen mode Exit fullscreen mode

2. Use the image to initiate the project.

cd my-projects/
docker run --rm -it -v "$(pwd):/app" -w /app laravel-installer:12 laravel new foobar
Enter fullscreen mode Exit fullscreen mode

3. Configure.

cd foobar/
vi .env
Enter fullscreen mode Exit fullscreen mode
# if you need to set up app port or DB connections, do it now
# otherwise there would be config caches, which made me pull my hair
APP_URL=http://localhost:8029
APP_PORT=8029
Enter fullscreen mode Exit fullscreen mode

4. Install and activate Laravel Sail.

# your location: my-projects/foobar/ of "host"
docker run --rm -it -v "$(pwd):/app" -w /app laravel-installer:12 bash

# your location: /app inside the container
composer require laravel/sail --dev
php artisan sail:install --devcontainer
Enter fullscreen mode Exit fullscreen mode

5. Start in devcontainer

Open the project in a devcontainer.
Inside the devcontainer, spin up dev server.

composer run dev
Enter fullscreen mode Exit fullscreen mode

If you hate VS Code or any other devcontainer compatible IDEs, you can try the hard way.

sail up -d
sail composer run dev
Enter fullscreen mode Exit fullscreen mode

That's all folks!

Top comments (0)