Create simple CI container pipeline with GitHub, Travis and DockerHub

High level overview:
Create Dockerfile and .travis.yml file in GitHub (in feature branch). Setup Travis CI to monitor master branch for finished pull requests. When master branch gets updated, Travis triggers docker build automatically and pushes the newly created image into DockerHub.

Once the image is in DockerHub registry, you can use it for your builds with Docker Compose or Kubernetes.

Travis CI
Our container will be built and pushed to DockerHub by Travis CI service. For security purposes we will need to define few environment variables in the Travis GUI, once created we can simply call them as bash variables within .travis.yml file.

Dockerfile:

FROM centos
ENTRYPOINT ["echo"]
CMD ["Hello world!"]

Regrading travis.yml file: it is good to think about it like a yaml file that is containing single line bash commands. Even variables are called the same way as in bash. We just basically want to run docker build, docker run and docker push commands as we would do in bash command line.

.travis.yml:

sudo: required

services:
  - docker

script:
  - docker build --tag coil/hello_world_travis_ci .
  - docker run coil/hello_world_travis_ci

before_deploy:
  - docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASS}

deploy:
  provider: script
  script: docker push coil/hello_world_travis_ci
  on:
    branch: master

This is how the final Travis build looks like. We can see that the image is built step by step and then the whole build process exits with exit code 0 (success).

Finally we can check our DockerHub account and we should see the newly built image.
The actual image for reference:
docker pull coil/hello_world_travis_ci:latest

Sources: