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

DHycken's avatar

Laravel, InertiaJS, Vue3, Docker Compose, Nginx setup struggles

Hello,

I'm at my wits end here and would appreciate any sort of feedback or ideas, think I've looked at every single "guide" on this topic with no success, seems like everyone does it a different way..

I wish to dockerize my webapp with Docker and Docker Compose. I'm using Laravel, InertiaJS, Vue3, Laravel Reverb, and PostgreSQL.

Before attempting to dockerize the solution I used Laravel Herd + pnpm run dev for vite hot reloading, I now wish to use bun and container nginx instead. I have tried to set it up with a dev profile for local dev and a prod profile for prod, getting dev to work is the main point right now.

I get no apparent errors except on Laravel Reverb and 404 not found in Laravel font on localhost:8080

the routes are generated properly for localhost:8080, including a subdomain I have.

the db seems correct and migrations run through, the www archive is properly copied to, php fpm is ran and ready to handle connections, vite server launches at APP_URL, localhost:8080

My leading theory is the directory structure is broken somehow since I constantly get 404 not found but I cannot see how, or maybe the ports?

FROM php:8.3-fpm-alpine

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

# 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

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

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
1 like
5 replies
jameswise's avatar

seems like you're on the right track, but there are a few areas you might want to double-check. First, ensure that your Nginx configuration is correctly pointing to the /var/www/public directory, as this is where Laravel expects the entry point to be. Double-check that your nginx.dev.conf file reflects this. Also, ensure that the nginx-dev container has access to the correct volumes and paths. The 404 errors could be due to Nginx not properly routing requests to the PHP container. Ensure that your fastcgi_pass directive in Nginx is pointing to the correct app service and port (app:9000). Additionally, verify that your Laravel routes are set up correctly and that there aren’t any typos or missing configurations. Lastly, check the logs of each container (docker-compose logs <service-name>) for any subtle errors that might not be immediately apparent. These logs can give you more context on where things might be going wrong.

DHycken's avatar

yea I dont know, I see no issues except for the constant 404 not found. It's weird to me, I've tried many different configurations but the 404 stays the same and the logs look normal to me at least.

I can cat the index.php file in the nginx-dev container so there shouldnt be permission errors. The logs from the containers look normal, no weird exits.

nginx-dev config looks to app:9000 for php-fpm

I reference port 9000:9000 in app container now, no difference.

I can visit my pgAdmin interface on port 5050.

Maybe it's related to my .env variables for the domain or url?

APP_DOMAIN=localhost:8080
APP_URL=http://localhost:8080

docker compose ps -a:

NAME        IMAGE                   COMMAND                  SERVICE     CREATED              STATUS                      PORTS
app         username/grindvakt:dev   "docker-php-entrypoi…"   app         About a minute ago   Up About a minute           0.0.0.0:9000->9000/tcp
bun         oven/bun:latest         "/usr/local/bin/dock…"   bun         About a minute ago   Up About a minute           0.0.0.0:3000->80/tcp
db          postgres:15-alpine      "docker-entrypoint.s…"   db          About a minute ago   Up About a minute           5432/tcp
nginx-dev   nginx:alpine            "/docker-entrypoint.…"   nginx-dev   About a minute ago   Up About a minute           0.0.0.0:8080->80/tcp
pgAdmin     dpage/pgadmin4          "/entrypoint.sh"         pgAdmin     About a minute ago   Up About a minute           443/tcp, 0.0.0.0:5050->80/tcp

app container:

  app:
    container_name: app
    env_file: 
      - .env.${COMPOSE_PROFILES:-dev}
    build:
      context: .
      dockerfile: Dockerfile
    image: username/grindvakt:${COMPOSE_PROFILES:-dev}
    volumes:
      - ./:/var/www
    working_dir: /var/www
    environment:
      - APP_ENV=${APP_ENV:-local}
      - DB_HOST=db
    ports:
      -  "9000:9000"
    depends_on:
      - db
    networks:
      - default
    profiles: [dev, prod]

nginx-dev:


  nginx-dev:
    profiles: [dev]
    container_name: nginx-dev
    restart: unless-stopped
    env_file: 
      - .env.dev
    image: nginx:alpine
    volumes:
      - ./:/var/www
      - ./nginx.dev.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "8080:80"
    depends_on:
      - app
    networks:
      - default

attempting to visit a page log:

nginx-dev  | 172.18.0.1 - - [19/Feb/2025:10:41:34 +0000] "GET / HTTP/1.1" 404 6622 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"
app        | 172.18.0.6 -  19/Feb/2025:10:41:34 +0000 "GET /index.php" 404
DHycken's avatar

Anyone knows if there is an actual "professional" guide on this topic? it feels like a mess. Some expose ports, some don't, some run php-fpm, some don't, some separate into containers, some don't, some create separate users for running processes, some don't. Not to mention that I have not yet even dockerized the prod/dev CICD with dockerhub/github.

Like this feels like such a basic thing that most developers must have done to launch their app or whatever, what is the recommended/best-practice way?

DHycken's avatar

I've narrowed it down to it being something wrong with how nginx deals with the inertiajs routes as a dd('test'); route renders fine.. I have however no idea now what could be wrong or why. example:

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');
...
DHycken's avatar
DHycken
OP
Best Answer
Level 1

After continuing to error search, it all came down to APP_DOMAIN=localhost:8000, apparently declaring the port there is a big no no as changing it fixed everything.

Please or to participate in this conversation.