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

yogeshgalav's avatar

How to run Laravel 9 with vite in docker?

I'm a fresher in docker. I tried with different methodologies but none of it succeded. 1.)Used different container for php and node. Problem: "npm run dev" require php and node in same terminal. 2.)Installed node inside php container. Problem: Ended with error module not found cli.js when running npm install. COPY --from=node:latest /usr/bin/node /usr/bin/node COPY --from=node:latest /usr/bin/npm /usr/bin/npm COPY --from=node:latest /usr/lib/node /usr/lib/node

  1. Tried with sail Problem: resources from port 5173 doesn't get load even after allocating port hence ended with blank page. vite.config.js server: { hmr: { host: 'localhost', }, }, docker-compose.yml sail ports: - 8001:80 - 5173:5173
0 likes
6 replies
messier42's avatar

This works for me, I'm using wsl2.

// vite.config.js
    server: {
        host: '0.0.0.0',
        hmr: {
            host: 'localhost'
        },
        watch: {
		    // https://vitejs.dev/config/server-options.html#server-watch
            usePolling: true
        }
    },
2 likes
jonnyhocks's avatar

Hoping I can jump in to hijack a bit of help here @sinnbeck . I have come across your article trying to set this up but so far I have not been able to get hot reload working. Here is my .lando.yml file for the node server section:

  node:
    type: node:16
    scanner: false
    ports:
      - 3009:3009
    build:
      - npm install

Here is the tooling section:

  npm:
    service: node
    cmd: npm

And here is my vite.config.js:

export default defineConfig({
  plugins: [
    laravel({
      input: ['resources/css/app.css', 'resources/js/app.js'],
      refresh: true,
    }),
  ],
  server: {
    https: false,
    host: true,
    strictPort: true,
    port: 3009,
    hmr: {host: 'localhost', protocol: 'ws'},
    watch: {
      usePolling:true,
    }
  },
});

I have rebuilt lando and restarted the vite server. When I visit my lando app address it does not get refreshed when I edit files. Hoping you can point me in any direction to get this up and running!

1 like
jonnyhocks's avatar

In true Rubber Duck style after posting this I went through and double checked everything against your article and also the laravel docs; I noticed that in my haste to delete everything in the blade file to make it was easier to read while debugging I also deleted the blinking @vite directive! Thanks again for your article!

Please or to participate in this conversation.