Docker file to intstall Node Js Application
Docker file to intstall NGINX
This Docker image allows you to create Expressjs web applications that run with Nginx in a single container.
- You should use it as a base image for other images, using this in your
Dockerfile
for NGNIX server:
FROM nginx
COPY default.conf /etc/nginx/conf.d/default.conf
# Your Dockerfile code...
- On same Diretory we ahve configuration for NGINX server
server {
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://webapp:9090;
}
}
- You shouldn't have to clone the GitHub repo. You should use it as a base image for other images, using this in your
Dockerfile
for expressjs application:
FROM node:12-alpine
# Your Dockerfile code...
- docker-compose file we have in root diretory with below code which having two services
- webapp - refer to node/express application . Context as
.
means location of dockerfile - nginx - refer to NGINX server . Dockerfile location is under
nginx-config
folder.
- webapp - refer to node/express application . Context as
version: "3.8"
services:
webapp:
build:
context: .
ports:
- "9090:8080"
nginx:
restart: always
build:
context: ./nginx-conf
ports:
- "9999:80"
- Building an image
$ docker-compose build
- Running containers
$ docker-compose up
- Stopping containers
$ docker-compose down
Created by @anuraggautam77