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.
21 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