Have you exposed Vite's dev server port in your docker-compose.yml? Also, how is your vite.config.js set up? It might help if you could share some of your configuration files.
Docker: Laravel NGINX MySQL (Local)
I am running on Mac OS
I am using PHPStorm and Docker. When I update my code file it does it job of updating it in the container too. However, when I am viewing my project on Safari (localhost). The changes do not happen unless I run "npm run build" in my container. Also when I use "npm run dev" localhost comes up with a blank page? Is that meant to happen? How do I dynamically have my work updated with my browser without having the need to manually update it?
You need to:
- Expose Vite’s development server to your host machine.
- Configure Vite to accept requests from outside the container.
Step 1: Update docker-compose.yml
Modify the app service to expose Vite’s default port (5173) and ensure it's properly bound to the host.
app:
...
ports:
- "9000:9000"
- "5173:5173" # Expose Vite's port
...
Step 2: Update vite.config.js
Modify vite.config.js to ensure it's accessible from your host.
...
export default defineConfig({
server: {
host: '0.0.0.0', // Listen on all network interfaces (required for Docker)
watch: {
usePolling: true, // Ensures file changes are detected inside Docker
},
strictPort: true,
port: 5173, // Ensure this matches the exposed port in docker-compose.yml
hmr: {
host: 'localhost', // Ensures HMR works when accessed via localhost
},
},
plugins: [
laravel({
input: 'resources/js/app.js',
refresh: true,
}),
...
],
});
How to Start Everything:
# 1. Start containers
docker-compose up --build -d
# 2. Run Vite inside the container
docker exec -it app npm run dev
# 3. Open http://localhost in Safari (HMR should work)
There are more optimized ways to use Docker with Laravel, but given your current setup, this approach is the quickest to get things running.
If you're looking for a more seamless integration, you can explore detailed guides on Laracasts:
- https://laracasts.com/series/the-docker-tutorial
- https://laracasts.com/discuss/channels/guides/getting-started-with-laravel-and-docker
You can also find plenty of resources with a quick Google search.
Please or to participate in this conversation.