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

DHycken's avatar

Dockerization leads to inertiajs routes not working

Hello,

I'm trying to dockerize my laravel, inertiajs, vue setup but I keep getting 404 results in laravel font.

I believe I have narrowed down the issue to inertiajs but what exactly is wrong here I am unsure about, something about how inertiajs serves routes(? a SPA?). I'd appreciate any insight or feedback on what could be wrong.

My stack is laravel, inertiajs, vue3, docker, docker compose, previously pnpm but now I wish to run bun instead, vite, laravel, postgresql.

The containers can ping eachother and networking looks ok, the routes are generated for localhost:8080, the database can be reached over pgadmin, the vite server serves at localhost, the composer installs, migrations run through.

I get no apparent errors in logs except for the constant 404 on localhost:8080 inertia routes, I tried with a test dd route and that renders fine

Route::get('/test', function () {
    return dd('test');
});

// Regular domain routes
Route::domain(config('app.domain'))->group(function () {

    // Standalone routes
    Route::get('/', [HomeController::class, 'welcome'])->name('welcome');
    Route::get('/about', [HomeController::class, 'about'])->name('about');
    Route::get('home', [HomeController::class, 'index'])->name('home');
	...

my nginx config (at the moment I'm only trying to get local development to work, prod comes later):

server {
    listen 80;
    server_name localhost;
    index index.php index.html;
    server_name localhost;
    root /var/www/html/public;

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

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

    location ~ /\.ht {
        deny all;
    }
}

the Dockerfile:

FROM php:8.3-fpm-alpine

# Install dependencies
RUN apk add --no-cache postgresql-dev libzip-dev \
    zip \
    unzip \
    curl \
    bash \
    nodejs \
    npm \
    && docker-php-ext-install pdo pdo_pgsql zip

# Install composer
COPY --from=composer/composer:latest-bin /composer /usr/bin/composer

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

WORKDIR /var/www/html

EXPOSE 9000

docker-compose:

docker ps:

NAME        IMAGE                   COMMAND                  SERVICE     CREATED         STATUS         PORTS
app         dhycken/grindvakt:dev   "docker-php-entrypoi…"   app         8 minutes ago   Up 8 minutes   0.0.0.0:9000->9000/tcp
bun         oven/bun:latest         "/usr/local/bin/dock…"   bun         8 minutes ago   Up 8 minutes   
db          postgres:15-alpine      "docker-entrypoint.s…"   db          8 minutes ago   Up 8 minutes   5432/tcp
nginx-dev   nginx:alpine            "/docker-entrypoint.…"   nginx-dev   8 minutes ago   Up 8 minutes   0.0.0.0:8080->80/tcp
pgAdmin     dpage/pgadmin4          "/entrypoint.sh"         pgAdmin     8 minutes ago   Up 8 minutes   443/tcp, 0.0.0.0:5050->80/tcp
0 likes
3 replies
DHycken's avatar

Wrote another test route for inertia to render a component, this route interestingly enough gives a complete white screen, no content or 404 not found. all other routes give 404 not found

Route::get('/i-test', function () {
    return Inertia::render('TestComponent');
});
DHycken's avatar

Continuing to error search on that white screen lead me to some other minor fixes (added a reverb container and changed nginx config a little), which now gives me a star-emoji green start-emoji blank screen (I guess some CSS from the layout is being rendered), and the browser console error: "Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL " from this line of code: const url = new URL(href.toString(), 'http://localhost') which traces back to the inertiaapp being mounted.

I still weirdly enough only have this green screen at this new test route, all other routes give 404 not found in laravel font. I'm confused.

DHycken's avatar
DHycken
OP
Best Answer
Level 1

It all came down to my env declaring the app domain as APP_DOMAIN=localhost:8000, and apparently declaring the port there is a big no no. I must have accidentally set it during the change. removing the port immediately fixed everything.

Please or to participate in this conversation.