Docker Automatic Pull Private Repository
On Image Startup

Here is how to make your Docker image automatically pull GitHub or BitBucket repository on starting up...

On your Github: create OAuth Token.

Go to https://github.com/settings/tokens

Generate new token and save it.


On your host working folder where you build the image, clone the repository, for example I put it on addons folder:

git config --global credential.helper store
cd addons
git clone REPOURL
Username: youraccount
Password: yourtoken



On you Dockerfile:

Install sudo and git  along with other packages required by the image.

RUN set -x; apt-get update && apt-get install -y --no-install-recommends git  sudo 


Copy local repo onto image, example :

COPY ./addons /opt/addons



Setup sudo user, eg odoo user, so that it can do sudo inside the container later:

RUN adduser odoo sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers


Done editing Dockerfile.


Now on entrypoint.sh, put the pull command at the container local repository folder :

sudo git -C /opt/addons http://token:<yourtoken>@github.com/<yourrepos> pull


Build the image as usual.

Now, every time you start the image, it will pull the latest version of your code from the repository!


Enjoy!


Need more trick on docker ? 

See my Udemy course: http://udemy.com/user/akhmaddaniel


Docker Automatic Pull Private Repository
vitraining, odoo indonesia
14 May, 2020
Share this post
Archive
Sign in to leave a comment
Docker Auto Build
Every GitHub or BitBucket Repository Push