Reputation: 21
with my Docker file
FROM node
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
CMD npm run dev
EXPOSE 4000
ENV NODE_ENV development
and docker compose
version: '3.8'
services:
app:
build: .
container_name: train_vite
working_dir: /app/
ports:
- "4000:4000"
volumes:
- ./:/var/www/html/app
command:
- npm run install
- npm run dev
environment:
NODE_ENV: development
and vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server:{watch:{
usePolling:true,
},
host:true,
strictPort:true,
port:4000
}
})
throws an error like this the command I run is docker compose up
I try to run a docker image with the app folder linked to the docker folder (volume) to see the changes on live.
Upvotes: 1
Views: 644
Reputation: 74620
A single command
can be specified in a compose definition as a string:
"/run/this/command witharg"
or an array of the command and its arguments.
[ "/run/this/command", "witharg" ]
The existing definition is attempting to execute a binary called
npm run install
with the argument npm run dev
Updating the example as a string:
version: '3.8'
services:
app:
build: .
container_name: train_vite
working_dir: /app/
ports:
- "4000:4000"
volumes:
- ./:/var/www/html/app
command: "npm run dev"
or as an array
command: [ "/usr/local/bin/npm", "run", "dev" ]
To run multiple commands at startup, the build would need a script in the container and that script used as a command
or entrypoint
.
Upvotes: 1