0

I'm trying to get Parcel Bundler to build assets from within a Dockerfile. But its failing with:

No entries found. at Bundler.bundle (/usr/local/lib/node_modules/parcel-bundler/src/Bundler.js:260:17) at ERROR: Service 'webapp' failed to build: The command '/bin/sh -c parcel build index.html' returned a non-zero code: 1

Here's my dockerfile:

FROM node:8 as base
WORKDIR /usr/src/app
COPY package*.json ./

# Development
FROM base as development
ENV NODE_ENV=development
RUN npm install
RUN npm install -g parcel-bundler
WORKDIR /usr/src/app
RUN parcel build index.html     <----- this is where its failing!
#RUN parcel watch index.html
# Uncomment to use Parcel's dev-server
#CMD [ "npm", "run", "parcel:dev" ]
#CMD ["npm", "start"]

# Production
FROM base as production
ENV NODE_ENV=production
COPY . .
RUN npm install --only=production
RUN npm install -g parcel-bundler
RUN npm run parcel:build
CMD [ "npm", "start" ]

NOTE: I'm trying to get this to run in Development mode first.

When I "log into" the container, I found that this command does fail:

# /bin/sh -c parcel build index.html

But this works:

# parcel build index.html 

And this works:

# /bin/sh -c "parcel build index.html"

But using these variations in the Dockerfile still do NOT work:

RUN /bin/sh -c "parcel build index.html"

or

RUN ["/bin/sh", "-c", "parcel build index.html"]

NOTE: I also tried 'bash' instead of 'sh' and it still didn't work.

Any ideas why its not working?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
jersey bean
  • 3,321
  • 4
  • 28
  • 43

1 Answers1

1

bash and sh are indeed different shells, but it shouldn't matter here. -c "command argument argument" passes the entire shell string to -c, whereas -c command argument argument only passes command to -c leaving the arguments to be interpreted as additional commands to the shell you're invoking. So the right invocation is indeed:

RUN parcel build index.html

or, if you prefer to explicitly do what Docker will do when it sees RUN followed by a string, you can do:

RUN [ "bash", "-c", "parcel build index.html" ]

But I don't think any of that is your problem. Looking at your docker file, I think you're probably either:

  • missing some files that Bundler needs ( you've only copied in package*.json at this point )
  • missing some additional config that Bundler needs to function (I don't see you explictly setting 'webapp' but that might be in a package*.json file)

I'd put my money on the first one.

erik258
  • 14,701
  • 2
  • 25
  • 31
  • 1
    see the difference bwteen shell and exec formats for docker CMD – Ijaz Ahmad Oct 25 '18 at 19:57
  • ah yes! I completely missed that. Thanks for pointing it out. I didn't copy over the other files because I'm use a bind mount while in development, which is specified when I start up the container (docker run -v...). Production mode would have transferred the files over. – jersey bean Oct 26 '18 at 00:15