Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install and run dev for laravel / vue on Docker container start

I am trying to automate installing and compiling JavaScript/Vue files and dependencies in a Laravel application in Docker. It is a simple Application that signs a Guestbook.

I have compiled a php:7.1.12-fpm container with all the required PHP Dependencies as well as Node 8.x packages. When the PHP container starts, npm 5.6.0 is available should I access it from the container's shell. Right now I have to go into this container and manually run "npm install" and "npm run dev" to install JavaScript Dependencies and compile Vue files.

I would like that to happen at the start of the docker-compose command. To do this I tried adding a Node container and having it execute these two commands. This is the docker-compose.xml for the Node container:

node:
    image: "node:8"
    user: "node"
    working_dir: /home/node/app
    environment:
      - NODE_ENV=production
    volumes:
      - ./web:/home/node/app
    expose:
      - "8081"
    command: npm install && npm run dev

Unfortunately running with the above docker-compose.xml for the Node container results in this error:

node_1     | npm ERR! code EINVALIDTAGNAME
node_1     | npm ERR! Invalid tag name "&&": Tags may not have any characters that encodeURIComponent encodes.
node_1     |
node_1     | npm ERR! A complete log of this run can be found in:
node_1     | npm ERR!     /home/node/.npm/_logs/2018-01-28T16_43_49_599Z-debug.log
laravelvuejsguestbook_node_1 exited with code 1

I suspect I have to somehow escape the && but I am not sure how to achieve this.

I would appreciate any assistance as to what needs to be done so that npm installs the dependencies and compiles the Vue files at the startup of the docker-compose command.

like image 400
Chandrashekar Singh Avatar asked Mar 07 '23 01:03

Chandrashekar Singh


1 Answers

Try changing your compose command statement to something as below -

command: bash -c "npm install && npm run dev"

PS - Tested with a sample package.json, it works when we use bash -c "" & not sh -c ""(default compose command run), not really sure about the exact reason though. Hope it can be of some help to you.

like image 155
vivekyad4v Avatar answered Mar 10 '23 09:03

vivekyad4v