Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

david_garden's avatar

Laravel+InertiaJS Docker

Hi has anyone attempted to run succesfully Laravel 10.x with InertiaJS + Vue in a Docker container, I'm trying to find a way to setup this stack but I'm kinda lost on how to make everything work properly.

Alternatively should I discard InertiaJS all together and follow the RESTful convention, I'd really like finish the Laravel Path but it is very discouraging for me having to do all of this research for DevOps stuff.

Also while I am here has anyone attempted to run Laravel with php-fpm and Inertia ? I can't seem to find anything about it.

As for php-fpm with docker I found this github repo should I be able to run InertiaJS by adding node to linux alpine ?

Feel free to ask for clarifications

0 likes
7 replies
LaryAI's avatar
Level 58

Certainly! Running Laravel with InertiaJS and Vue in a Docker container is quite feasible. Below is a basic setup to get you started. This setup assumes you have Docker and Docker Compose installed on your system.

First, you'll need a Dockerfile for your application. Here's an example Dockerfile that sets up PHP with the necessary extensions for Laravel, as well as Composer for dependency management:

FROM php:8.1-fpm-alpine

# Install system dependencies
RUN apk add --no-cache git curl libpng libpng-dev libjpeg-turbo-dev libwebp-dev zlib-dev libxpm-dev gd-dev zip libzip-dev

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql gd zip exif pcntl

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www

# Copy existing application directory contents
COPY . /var/www

# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]

Next, you'll need a docker-compose.yml file to define your services:

version: '3.8'
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: laravel-inertia-app
    container_name: laravel-inertia-app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - laravelnet
    environment:
      - "DB_HOST=db"
      - "DB_PORT=3306"
      - "DB_DATABASE=laravel"
      - "DB_USERNAME=root"
      - "DB_PASSWORD=root"

  db:
    image: mysql:5.7
    container_name: laravel-inertia-db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: laravel
      MYSQL_ROOT_PASSWORD: root
    networks:
      - laravelnet
    volumes:
      - dbdata:/var/lib/mysql

  nginx:
    image: nginx:alpine
    container_name: laravel-inertia-nginx
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./:/var/www
      - ./nginx/conf.d:/etc/nginx/conf.d/
    networks:
      - laravelnet

networks:
  laravelnet:
    driver: bridge

volumes:
  dbdata:
    driver: local

You'll also need a default Nginx configuration file for your Laravel app. Create a nginx/conf.d/app.conf file with the following content:

server {
    listen 80;
    server_name localhost;
    root /var/www/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php index.html index.htm;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Regarding InertiaJS, you don't need to discard it. You can integrate it with Laravel and Vue as you would normally do without Docker. The Docker setup is just for the environment; it doesn't affect how you write your Laravel or Vue code.

For the front-end assets, you can use Laravel Mix to compile your Vue components. You might need to install Node.js and npm in your Docker container or use a separate container for asset compilation.

To add Node.js to your Docker container, you can modify your Dockerfile to include Node.js installation commands:

# Install Node.js (and npm)
RUN apk add --update nodejs npm

After setting up your Docker environment, you can run docker-compose up -d to start your containers. Your Laravel application should now be accessible at http://localhost:8080, and you should be able to use InertiaJS with Vue as intended.

Remember to run composer install and npm install to install your PHP and JavaScript dependencies, and use npm run dev or npm run production to compile your assets.

This setup should give you a good starting point. You can customize it further based on your specific requirements.

gych's avatar

Can you share you current DockerFIle

david_garden's avatar

Hi @gych so after browsing a bit github I found a solution that did actually fit my requirements.

This is the original repo

I adapted it in this way (I'll be skipping the conf.d folder) docker-compose.yml

version: "3.8"
services:
  laravel:
    build: .
    container_name: laravel
    environment:
      PHP_OPCACHE_ENABLE: 1
      PRODUCTION: 0
    ports:
      - 8081:80
    volumes:
      - .:/opt/laravel
      - vendor-data:/opt/laravel/vendor
      - storage-data:/opt/laravel/storage
    healthcheck:
      test: ["CMD", "curl", "-f", "http://laravel/"]
      interval: 30s
      timeout: 10s
      retries: 3

  db:
    image: mysql:8.3
    container_name: mysql
    restart: unless-stopped
    environment:
      - MYSQL_DATABASE=${DB_DATABASE}  // from .env file
      - MYSQL_USER=${DB_USERNAME}  // from .env file
      - MYSQL_PASSWORD=${DB_PASSWORD}  // from .env file
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}  // from .env file
    volumes:
        - dbdata:/var/lib/mysql
    ports:
        - 3307:3306
volumes:
  vendor-data:
  storage-data:
  dbdata:

Dockerfile

FROM php:8.3-fpm-alpine

# Set working directory
WORKDIR /opt/laravel

# Install additional packages
RUN apk --no-cache add \
    nginx \
    supervisor \
    nodejs \
    npm \
    && docker-php-ext-enable opcache \
    && docker-php-ext-install pdo_mysql

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Copy Nginx configuration
COPY conf.d/nginx/default.conf /etc/nginx/nginx.conf

# Copy PHP configuration
COPY conf.d/php-fpm/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf

COPY conf.d/php/php.ini /usr/local/etc/php/conf.d/php.ini

COPY conf.d/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini

# Copy Supervisor configuration
COPY conf.d/supervisor/supervisord.conf /etc/supervisord.conf

# Copy Laravel application files
COPY . /opt/laravel

# Set up permissions
RUN chown -R www-data:www-data /opt/laravel \
    && chmod -R 755 /opt/laravel/storage

# Scheduler setup

# Create a log file
RUN touch /var/log/cron.log

# Add cron job directly to crontab
RUN echo "* * * * * /usr/local/bin/php /opt/laravel/artisan schedule:run >> /var/log/cron.log 2>&1" | crontab -

# Expose ports
EXPOSE 80

ADD --chmod=0755 entrypoint.sh /root/entrypoint.sh

ENTRYPOINT ["/root/entrypoint.sh"]

In the entrypoint.sh I just changed the .env file it points to.

I basically slapped node and npm into the php-fpm image because it is just alpine linux with some additional stuff, however I would like to know your opinion about this type of approach because I saw that in other repos some devs decided to separate fpm and node despite sharing the exact same folders, would you consider my approach production ready ?

Thanks.

1 like
Robstar's avatar

@david_garden Problem with these random Docker files is that you'll need to maintain them and Docker / DevOps knowledge is required. I normally find community supported solutions like LaraDock or http://devilbox.org. Of course Laravel's own "Sail" is also an option.

1 like
david_garden's avatar

@Robstar Your solutions don't solve my specific issue which is about InertiaJS, please delete your answers to avoid cluttering up the discussion

Robstar's avatar

There are so many options and dev-ops isn't really something you need to delve into.

You can get Laravel Herd up and running (on Windows 11 /Mac) within 5 minutes. See https://herd.laravel.com (free version doesn't have MySQL, buy SQLite can be obviously be used for free).

If you'd like to use Docker there are a lot of options. My own preference is LaraDock, see https://laradock.io. That will take around 10 minutes to setup and requires you learn two or three commands. For example, within that 10 minutes you could have nginx, PHP 8.3, MySQL, Mailhog (for local mail catching) and Redis running.

If using Docker, it's always faster to run Vite on your host system, not within the Docker container.

Please or to participate in this conversation.