build node application with Docker

This commit is contained in:
Steffen Vogel 2017-07-22 04:03:10 +02:00
parent 355e524348
commit 09bf7f1b38
4 changed files with 30 additions and 11 deletions

View File

@ -1,2 +1,3 @@
node_modules/
doc/
npm-debug.log

View File

@ -1,10 +1,19 @@
FROM nginx:stable-alpine
FROM node:8.2
# Copy frontend files and make them accesible to nginx
RUN mkdir /www
COPY build /www
RUN chown nginx:nginx -R /www
RUN chmod -R 0755 /www
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Copy nginx configuration
COPY etc/nginx/villas.conf /etc/nginx/conf.d/default.conf
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
VOLUME /usr/src/app/build
# Bundle app source
COPY . /usr/src/app
RUN npm run build
EXPOSE 80
CMD [ "npm", "start" ]

View File

@ -8,14 +8,23 @@ networks:
villas:
services:
# The VILLASweb frontend
# Build the frontend with node into a Docker volume
# This container does nothing useful beside providing an
# assets container to the nginx service
frontend:
build:
context: .
command: "/bin/true"
nginx:
image: nginx:stable-alpine
ports:
- "80:80"
- "443:443"
restart: always
volumes:
- "./etc/nginx/villas.conf:/etc/nginx/conf.d/default.conf"
volumes_from:
- frontend
networks:
villas:

View File

@ -27,7 +27,7 @@ server {
# frontend location
location / {
root /www;
root /usr/src/app/build/;
}
# error pages