I've a repo with angular and nodejs. I performed in jenkins:
# install globally
npm install -g bower
npm install -g gulp
# install
bower install
npm install
# build dist folder
gulp build
Now I have in my root:
Dockerfile.nginx Dockerfile.nodejs README.md bower.json dist gulp.config.js gulpfile.js node_modules package.json server.js src
I'm copying the dist folder inside my nginx container. So I'm hosting the angular. (with a dockerfile)
FROM nginx
# copy folder
COPY dist /usr/share/nginx/html/dist
I'm copying: gulp.config.js gulpfile.js node_modules server.js
to my nodejscontainer. (also with a dockerfile)
FROM node
# Create app directory
RUN mkdir -p /usr/src/www
WORKDIR /usr/src/www
# copy
COPY node_modules /usr/src/www/
COPY gulpfile.js /usr/src/www/
COPY gulp.config.js /usr/src/www/
COPY server.js /usr/src/www/
EXPOSE 8080
CMD [ "node", "server.js" ]
I run the 2 containers but the nginx does not communicate with the nodejs
EDIT1: Start containers:
docker run -d -p 8888:8888 --name "nodejs" localhost:5000/test/nodejs:1
docker run -d -p 80:80 --name "nginx" localhost:5000/test/nginx:1
EDIT2: My nginx.conf looks like this:
http {
upstream node-app {
least_conn;
server nodejs:8888 weight=10 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
location /dist {
alias /usr/share/nginx/html/dist/;
}
location ~* /api {
#location / {
proxy_pass http://node-app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}
My server.js looks like:
app.get('/api/hello', requestProxy({
url: xxx + "/hello"
}));