From f866380d1152cb3575ec7a8a7bcb328fc465a90d Mon Sep 17 00:00:00 2001 From: James Filtness Date: Fri, 30 Mar 2018 12:22:47 +0100 Subject: [PATCH] Docker --- Dockerfile.dev | 17 +++++++++++++++++ Dockerfile.nginx | 2 ++ docker-compose.yml | 17 +++++++++++++++++ nginx.conf | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 Dockerfile.dev create mode 100644 Dockerfile.nginx create mode 100644 docker-compose.yml create mode 100644 nginx.conf diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..2817f6e --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,17 @@ +# Use the official Node 8 runtime as a parent image +FROM node:boron + +# Set the working directory to /app +WORKDIR /app + +# Copy the current directory contents into the container at /app +COPY . /app + +# Install node dependencies +RUN npm install + +# Run node app when the container launches +CMD ["node", "."] + +# Make port 3000 available to the world outside this container +EXPOSE 3000 diff --git a/Dockerfile.nginx b/Dockerfile.nginx new file mode 100644 index 0000000..01bad77 --- /dev/null +++ b/Dockerfile.nginx @@ -0,0 +1,2 @@ +FROM nginx +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b046419 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.0' +services: + app: + # If a context is not provided Docker looks for a file named "Dockerfile" + build: + context: . + dockerfile: Dockerfile.dev + volumes: + - .:/app + nginx: + build: + context: . + dockerfile: Dockerfile.nginx + ports: + - 8080:8080 + depends_on: + - app diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..1dc1772 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,38 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + + upstream node_app { + # By default docker-compose sets up a single network for your app. + # Each container for a service joins the default network and is both reachable by other containers on that network, + # and discoverable by them at a hostname identical to the container name. + # https://docs.docker.com/compose/networking/ + server app:3000; + } + + server_tokens off; + + # Define the MIME types for files. + include mime.types; + default_type application/octet-stream; + + # Speed up file transfers by using sendfile() + sendfile on; + + server { + listen 8080; + server_name localhost; + + location / { + proxy_pass http://node_app; + proxy_http_version 1.1; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + } + } +}