Dockerfile COPY specific branch

My Dockerfile builds an image copying the content of the current working directory, but always uses the master branch. I would like to specify a branch during the COPY or ADD operation.

FROM node:10.18.0-stretch
EXPOSE 81 8080
RUN apt-get update; \ apt-get install -y \ ssh \ git-core \
COPY ./ /var/www/app_source
WORKDIR /var/www/app_source
RUN npm i npm@latest \ && npm install \ && npm install pm2@latest -g
CMD [ "pm2-runtime", "app.js" ]

The above will always build the image using the master branch, whereas I'd like to specify a staging branch. A less elegant solution is to git clone -b staging and build from that directory which will work given there's no other branch there.

However, I'd like to continue developing on the current master branch but build images using any branch on my local workstation.

Any ideas, responses are appreciated.

2

1 Answer

if I understand right, you have copied your git-directory in the image. If so, you should start with the proper git checkout command to bring the proper branch to the front.

git checkout specificbranch

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like