2

We have an app written in Angular

We will use an nginx container to host the angular but the problem is where we have to perform the npm install for creating the /dist folder in angular. Do we have to perform it in the dockerfile of our nginx-webserver or is this against the rules?

1 Answer 1

1

You are obviously using node as your dev server and want to use NGINX as your prod server? We have a similar setup

this is how we do it ...

in our dev environment, we have /dist on .gitignore

on a push to git we have a Jenkins job that does a build (this does the npm install inside a Jenkins build server)

on a successful Jenkins job we do a docker build (a downstream job), the docker build copies the /dist files into the docker image

we then do a docker push

the resulting docker image can be pulled from any server - hope that helps

would welcome your thoughts :)

PS The problem with doing the npm install during the docker build is that your docker container becomes messy. You end up installing loads of software inside it just for setup purposes.

All you really want in your docker image is NGINX serving up your build files.

This is why we do not do an npm install during the docker build.

Sign up to request clarification or add additional context in comments.

9 Comments

A comment from our resident expert ... if you are building a production image then you want as little as possible installed inside it - hence the Jenkins job outside of docker
How do you copy your /dist to the image?
Will it be an issue when your Jenkins is also running in Docker?
no its not an issue - conceptually you could do ... ONE Jenkins docker container ... ONE Jenkins build slave docker container ... Here the build slave would need docker installed ... This would require docker being installed within a docker container - WHICH THANKFULLY IS VALID :)
Thanks. can you maybe give an example of how your folders and files are stored in your repository. So it's possible to have 2 dockerfiles in it. (for example first: /angular and /nodejs. than /anguler/dockerfile and /angular/stuff. /nodejs/dockerfile and /nodejs/package.json and /nodejs/index.js
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.