undefined
undefined

Reputation: 3632

Working at 2 WORKDIR simultaneously DOCKEFILE

I am trying to reduce the buildtime for my docker image.

I have to install node dependency for backend and bower dependency from UI.

Right now it runs sequentially from 2 different workdir.

WORKDIR $CLIENT_DIR
RUN bower --allow-root install

WORKDIR $SERVER_DIR
RUN npm install

Since both are independent on each other, its annoying to wait for bower install to finish for installing npm install.

I think docker will have better way to handle such cases.

I think my question is clean, and doesn't need more info. Please let me know if I should provide some other infor as well.

Upvotes: 1

Views: 35

Answers (1)

Yaron Idan
Yaron Idan

Reputation: 6765

Since docker is building its images in layers, you will not be able to run this dockerfile as it is in parallel.
Here are 2 workarounds I can think of that might allow for parallelism, but IMO are a bigger effort than the value they will give you -

  1. You can run both commands in the background, and then execute a bash script that checks if the processes have finished their work.
  2. You can leverage multistage build by building 2 images - one with your npm dependencies and another with bower dependencies, and then get a third build which gets the artifacts created by the 2 previous builds.

Upvotes: 1

Related Questions