How to install gulp on a docker with docker-compose
Asked Answered
M

3

8

I am using docker compose and this is my yaml file

web:
  dockerfile: Dockerfile-dev
  build: .
  command: gulp
  volumes:
    - .:/app
  ports:
    - '9001:9001'

and here is my docker file

FROM node:0.12.7

RUN npm install -g bower gulp

ADD . /app
WORKDIR /app

RUN bower install --allow-root

Then i run

docker-compose -f docker-compose-dev.yml build
docker-compose -f docker-compose-dev.yml up

But i get the following error

Recreating web_web_1...
Attaching to web_web_1
web_1 | [07:39:08] Local gulp not found in /app
web_1 | [07:39:08] Try running: npm install gulp
web_web_1 exited with code 1
Gracefully stopping... (press Ctrl+C again to force)**strong text**

I have tried adding the line RUN npm install gulp before and after WORKDIR /app to get it installed locally but i get the same error

Help

Marilumarilyn answered 23/10, 2015 at 7:45 Comment(1)
I know nothing about gulp, but your Dockerfile should end with a CMD or ENTRYPOINT I think, see docs.docker.com/reference/builder/#cmd and docs.docker.com/reference/builder/#entrypointBorgeson
F
10

You need to run npm install gulp AFTER WORKDIR /app, so that gulp is installed locally in node_modules/gulp. But you already did that and having the same error. It's because in your docker-compose-dev.yml, you are mounting host directory as /app volume inside docker container. So local changes in /app directory is lost when you are running the container.

You can either remove volumes from docker-compose-dev.yml or run npm install gulp in host machine.

Fabriane answered 23/10, 2015 at 11:58 Comment(2)
This was spot on, thanks so much. i have literally spent 1.5 days working on thisMarilumarilyn
This is it. Removing the volumes section made the container run. Thanks.Baxley
A
0

You can create startup.sh

npm install bower gulp
bower install --allow-root

(or whatever you need to run when container fires) then your Dockerfile should execute startup.sh

...
CMD ["/startup.sh"]

the startup script will be executed AFTER the dir is mounted by docker-compose.

I would also suggest to mount node_modules in the temporary file system declaring in the docker-compose.yml:

volumes:
- .:/app
- /app/node_modules
Amalamalbena answered 6/2, 2017 at 15:3 Comment(0)
J
0

To future googlers:

check if you do not have Node image in production environment. It won't work and you will hate life.

For gulp to work you should have development env set like this:

FROM node:latest AS build

ENV NODE_ENV=development
Jewelljewelle answered 11/9 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.