segunda-feira, 29 de agosto de 2016

Build and update Docker Containers automatically from GitHub

:: Some findings from this weekend ::
Build and update Docker Containers automatically from GitHub 
To have Docker Hub build and update containers automatically for you, triggered by any commit to GitHub:
a)      You’ll need to authorize Docker Hub to access you GitHub
       https://hub.docker.com/account/authorized-services/          
 
b)      Then you'll  be able to
c)       Fill or confirm the “Repository Namespace & Name”, and it will create it for you; 
d)      Next, go to 
And select where the Dockerfile file is located (inside that repo) – save changes; you can manually trigger it too from here:
(Note: you have to have a Dockerfile present there in the repo – see further notes bellow) 
e)      Check the build details to see when it has finished (may take minutes, or hours if your dockerfile has something wrong):
The tricky part is really the dockerfile – 4am+ last Saturday to get it right, namely the RUN and CMD (first: run a command – second, start a daemon, etc.)
Here are the files for react-tutorial mentioned in my prev message:

a)      Node.JS (the one that is more simple – npm install is necessary, because we need npm modules that aren’t there at the repo):

FROM node

MAINTAINER Filipe Bento
<fbento@ebsco.com>

RUN
mkdir -p /code

WORKDIR
/code

RUN git clone
--depth 1 --single-branch https://github.com/fmbento/react-tutorial.git /code

RUN npm install

EXPOSE
3000

CMD
["node", "server.js"]


b)      And Python:

FROM python

MAINTAINER Filipe Bento 
<fbento@ebsco.com>

ENV DEBIAN_FRONTEND noninteractive

RUN apt
-get update --quiet > /dev/null && \
  apt
-get install --assume-yes --force-yes -qq \
  git 
&& \
  apt
-get clean && \
 
rm -rf /var/lib/apt/lists/*

RUN
mkdir -p /code

WORKDIR
/code

RUN git clone
--depth 1 --single-branch https://github.com/fmbento/react-tutorial.git /code && \
    pip install
-r requirements.txt

RUN
sed -i "s/app.run(port=int(os.environ.get(\"PORT\",3000)))/app.run(debug=True, host='0.0.0.0', port=int(os.environ.get(\"PORT\",3000)))/g" server.py

EXPOSE
3000

CMD
["python", "server.py"]


Quite simple, once you master what’s doing.
Note that you can also compile containers right from your workspace using Docker Compose – here’s a good page about it (Dockerizing a PHP Application).

Next:  Testing your specific stacks solutions (NodeJS / Ruby / Python / Go, etc.) with Heroku
Enjoy!
.

Sem comentários:

Enviar um comentário