How to dockerize a React Vite project? #23
|
How can I use auto-dockerize with a React Vite project and what port will it use? |
Replies: 1 comment
|
Make sure you have Docker Desktop installed and that it is version 2.22 or higher, since that is when Compose Watch was introduced. You can check with Update vite.config.js Write your Dockerfile Write your docker-compose.yml Start it From this point the workflow is fully automatic. You edit a component, Watch syncs it into the container, Vite picks it up and updates the browser. You add a package to package.json, Watch triggers a rebuild and restarts with the new dependency installed. |
Make sure you have Docker Desktop installed and that it is version 2.22 or higher, since that is when Compose Watch was introduced. You can check with
docker compose versionin your terminal.Update vite.config.js
As covered earlier, this is the first thing you do before touching any Docker file. Set host to 0.0.0.0 and explicitly set the port to 5173. Without this, the container will run but your browser will never reach it.
Write your Dockerfile
This is a development Dockerfile, so its only job is to install dependencies and start the Vite dev server. It does not build for production. The steps inside it are: choose a Node base image, set a working directory, copy package.json in first, r…