I have been trying to deploy my express web application to nginx web server.
This is my directory structure.
express-app
frontend
public
/*all resources, images etc*/
src
/*all js files*/
views
/*html files*/
package.json
index.js //server file
Dockerfile //image for front end
backend
src
server.js
package.json
Dockerfile //image for backend
proxy
Dockerfile //???
proxy.conf //???
docker-compose.yml
I have successfully dockerised my application and it works fine. But i am little confused in how do i create Dockerfile for nginx and proxy.nginx so that nginx could be used as a web server for my application. The Dockerfiles for frontend and backend work.
Dockerfile for front end:
FROM node:carbon
RUN mkdir -p /usr/src/frontend
# Create app directory
WORKDIR /usr/src/frontend
COPY package*.json ./
RUN npm install && npm install gulp -g
# Bundle app source
COPY . .
CMD ["gulp","sass","js-global","js-pages"]
EXPOSE 8081
CMD [ "npm", "start" ]
Dockerfile for backend:
FROM node:carbon
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
COPY . .
ENV MONGODB_URL=mongodb://mongo/db3
ENV BACKEND_HOST_PATH=http://localhost:5000/
EXPOSE 5000
CMD ["npm", "start"]
I am using docker for windows. How do I make a dockerfile and conf file for nginx so that it acts as a web server for my application?
I think there is two way.
first, simple nginx isn't dockernize. You setup nginx in docker host. and just nginx proxy.
#front
location / {
proxy_pass http://localhost: 8081;
}
#backend
location / {
proxy_pass http://localhost: 8081;
}
second, if you want to using dockernize about nginx.
docker network create test
docker run --name nginx --network=test
docker run --name front --network=test
docker run --name backend --network=test
you excute above command. nginx container connect front, backend by name; this is like hosts file.
Do you understand? Did I understand what do you want?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.