OK, I think you can use environment variables to control the configuration of your application at runtime, instead of hardcoding it in your source code. To achieve what you're looking for, you can use environment variable files to store your configuration and use them in your Dockerfile. Create a .env.production, .env.development, and .env.staging file for each environment you need to configure. In your Dockerfile, use the ARG instruction to pass the environment variable file to the image at build time.
ARG NODE_ENV
# set environment file based on the argument
ENV ENV_FILE=.env.$NODE_ENV
# copy environment file to container
COPY $ENV_FILE /app/.env
# build the app
RUN vite build
# copy the built files to the nginx directory
COPY dist /usr/share/nginx/html
# run nginx
CMD ["nginx", "-g", "daemon off;"]
To build the image for each environment, you can pass the NODE_ENV argument to the docker build command.
# build the production image
docker build --build-arg NODE_ENV=production -t myapp:production .
# build the development image
docker build --build-arg NODE_ENV=development -t myapp:development .
# build the staging image
docker build --build-arg NODE_ENV=staging -t myapp:staging .
when you run the container, you can specify the environment-specific image that you built earlier.