[Vuejs]-Dockerfile returns built dist folder

0👍

I suggest that you wanna serve dist folder using nginx.
You should use multi stage build for this https://docs.docker.com/develop/develop-images/multistage-build/

Dockerfile

FROM node:14.14.0-stretch as build
WORKDIR '/app'
COPY package*.json ./
RUN npm install
COPY . ./
RUN env
RUN npm run generate

# create cdn stage from nginx image
FROM nginx:stable-alpine as cdn

# copy nginx config to serve files from /data/www
COPY nginx.conf /etc/nginx/nginx.conf

# copy built files from build stage to /data/www
COPY --from=build /app/dist /data/www

# nginx listen on port 80
EXPOSE 80
CMD [ "nginx" ]

nginx.conf

events {
    worker_connections 1024;
}

http {
    server {
        location / {
            root /data/www;
        }
    }
}

docker-compose.yml

version: '2.4'

services:
  nginx-cdn:
    build:
      context: path/to/Dockerfile
      target: cdn
    ports:
      - '80:80'

Leave a comment