Skip to content

Instantly share code, notes, and snippets.

@matteomallus
Last active June 15, 2020 18:29
Show Gist options
  • Save matteomallus/d07bf1ec086676b74a3169d5921b5bd7 to your computer and use it in GitHub Desktop.
Save matteomallus/d07bf1ec086676b74a3169d5921b5bd7 to your computer and use it in GitHub Desktop.
Dockerfile for vue build multistage
=================================================================================
## Dockerfile MULTISTAGE
FROM node:12.11.1-alpine as node_build
RUN apk add --update --no-cache nginx==1.14.2-r5
RUN npm i -g yarn@1.17.3
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn install
COPY . .
RUN yarn run build
FROM nginx:1.18.0-alpine-perl
RUN mkdir -p /var/log/nginx
RUN mkdir -p /var/www/html
COPY nginx_config/nginx.conf /etc/nginx/nginx.conf
COPY nginx_config/default.conf /etc/nginx/conf.d/default.conf
COPY --from=node_build /usr/src/app/dist/ /var/www/html/
RUN chown nginx:nginx /var/www/html
=================================================================================
## DOCKERFILE SINGLE STAGE
FROM node:12.11.1-alpine
RUN apk add --update --no-cache nginx==1.14.2-r5
RUN npm i -g yarn@1.17.3
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn install
COPY . .
RUN yarn run build
RUN mkdir -p /var/log/nginx
RUN mkdir -p /var/www/html
COPY nginx_config/nginx.conf /etc/nginx/nginx.conf
COPY nginx_config/default.conf /etc/nginx/conf.d/default.conf
RUN cp -r dist/* /var/www/html
RUN chown nginx:nginx /var/www/html
# clean up
RUN rm -rf /usr/src/app
RUN npm uninstall -g yarn
=================================================================================
## default.conf
server {
location / {
root /var/www/html;
try_files $uri $uri/ /index.html;
}
}
=================================================================================
## nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile off;
keepalive_timeout 60;
include /etc/nginx/conf.d/*.conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment