5

Im trying to exec bower install on node:4.1.2 docker container from the dockerfile.

Part of my dockerfile is like this:

#Install bower to command line
RUN npm install -g bower

# Define the host folder that will contain the code
WORKDIR /application

# Copy src to application host folder**
ADD . /application

# RUN move to /application/public/webapp where there is a bower.json file and install it**
RUN cd public/webapp && bower install --allow-root --config.interactive=false

ENTRYPOINT ["npm"]
CMD ["start"]

I build it and up it.

This dockerfile does not build the bower_components folder despite of showing:

Step 9 : RUN cd public/webapp && bower install --allow-root --config.interactive=false
 ---> Running in 937ad6c21887
/application/public/admintool
bower angular#1.4.7         not-cached git://github.com/angular/bower-angular.git#1.4.7
bower angular#1.4.7            resolve git://github.com/angular/bower-angular.git#1.4.7
bower angular#1.4.7           download https://github.com/angular/bower-angular/archive/v1.4.7.tar.gz
bower angular#1.4.7            extract archive.tar.gz
bower angular#1.4.7           resolved git://github.com/angular/bower-angular.git#1.4.7
bower angular#1.4.7            install angular#1.4.7

angular#1.4.7 bower_components/angular

If I get into the container, bower is recognized as a command (it installed it). Running bower install from /application/public/webapp works if Im inside the container. From dockerfile it just does not do anything. Neither it complains.

Does anyone knows why?

kitimenpolku
  • 2,604
  • 4
  • 36
  • 51
  • Could you show the log of `bower install` when running the command manually outside the container? – michaelbahr Oct 27 '15 at 13:37
  • I dont have installed bower in my machine. Is this an issue? Im new to docker. Inside the container the bower command exists and works. – kitimenpolku Oct 27 '15 at 13:39
  • 1
    Docker containers behave counterintuitive with background processes. Only a process that "grabs" your terminal (no background process) will keep a docker container alive. I don't know much about bower install, but this is quite a common issue. That is why I asked for the logs of bower install. – michaelbahr Oct 27 '15 at 13:41
  • Look at CMD or ENTRYPOINT, this should be the last line of your Dockerfile – user2915097 Oct 27 '15 at 13:45
  • Yes, I exec npm script contained in package.json – kitimenpolku Oct 27 '15 at 13:48
  • @michaelbahr by echoing the directory just after running bower install I see that the bower_component folder was created. It seems that it is removed as you just said. So... what's the right way of doing a "build" in docker? Is it in the package.json when CMD? – kitimenpolku Oct 27 '15 at 13:59

1 Answers1

1

Are you perhaps mounting a volume from your host into the container through your docker-compose.yml file or the -v parameter in your docker run command?

I ask because you mentioned you don't have bower installed on your machine, so you presumably don't have the bower_components folder in the host copy of your codebase. If you then run your container and mount the volume containing the source on your host into the container then the bower_components folder would be lost, explaining why it seems to disappear from the container.

I would first test to see if this is indeed the problem by not mounting any volumes from your host and seeing if the bower_components folder then remains after you build and run the container. You could then install bower on your host and run bower install so the mounted volume doesn't cause issues while you're in development.

Scott Covert
  • 111
  • 1