Similar to this question I want to run a vite dev server inside a docker container. The motivation is basically that I want to compose it with a backend server and distribute an easily repeatable environment to teammates.
However, when I run the container, it immediately exits with no logs other than
< docker run -p 8080:8080 hiking-weather-frontend
> hiking-weather-frontend@0.0.0 dev
> vite "--host"
The same happens when I switch to a container terminal and run npm run dev
manually -- it immediately returns with the above message.
The Dockerfile:
WORKDIR /usr/app
# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./
# Install project dependencies
RUN npm install
RUN npm i -g vite
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .
EXPOSE 8080
CMD ["npm", "run", "dev", "--", "--host"]
vite.config.js
:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
server: {
host: '0.0.0.0',
watch: {
usePolling: true
}
}
})
package.json
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
server: {
host: '0.0.0.0',
watch: {
usePolling: true
}
}
})
Would be eternally grateful for any input. Thanks!