Docker

Docker Hub – Build Hooks

I tried out the Docker Hub post_push hook script today with my automated build and it works great.  This link has all the details around more advanced Docker Hub build scripting.

What I tried using the post_push script for was to tag my mainline build (latest) with another specific tag (release).

Steps to implement:

  1. Create a hooks folder in my GitHub repo.
  2. Create a script called “post_push” under the hooks folder that will tag the latest image with my release number.

    #!/bin/bash
    set -e
    tagStart=$(expr index “$IMAGE_NAME” ūüôā
    repoName=${IMAGE_NAME:0:tagStart-1}
    docker tag $IMAGE_NAME ${repoName}:18.3.1
    docker push ${repoName}:18.3.1

The end results is the following:

postpushdocker.png

So a possible use-case would be to have a Jenkins job that gets triggered when your Dockerfile changes in GitHub and updates the release version in the “post_push” script, then triggers the Docker Hub job.

dockericon

Docker Goodies – Frequent Commands

Noting some of the usual Docker commands I run for future reference…

  • Start Docker daemon = systemctl start docker
  • View running Docker images = docker ps
  • View all images on the server = docker images or docker image ls
  • Remove all images on the server (dangling and unused) = docker images prune -a
  • Build my image = docker build -f <dockerfile_path> .
  • Run my Docker image and check Ansible version = docker run –rm -it <image_id> –version
  • Tag new image =¬†docker tag <image> devopsunleashed/ansible:3.31.1
  • Login to Docker Hub =¬†docker login -u <user> -p <pw>
  • Push image to Docker Hub = docker push¬†devopsunleashed/ansible:3.31.1

Awesome Docker command cheat-sheet (link)

dockericon

Docker Build Error – Temporary Error (try again later)

When building a new Docker image from Alpine 3.6 (RUN apk –update add –virtual build-dependencies gcc ...), I encountered the following errors:

I found 2 separate solutions to work around these errors.

  1. Utilize “–network=host” when building the new image.
    • This option will force the Dockfile’s “Run” instruction to use the Docker host network stack
  2. Set the Docker DNS server globally on the build host.¬† Add “-dns x.x.x.x” to the¬†DOCKER_OPTS variable.¬† After you make this property change, you will need bounce the Docker daemon.

I’m also going to try to update my Dockerfile to work around this issue, but wanted to get this info documented before I forget.

dockericon

New Docker\Ansible container per Playbook execution?

dockericon

What would it look like to setup a job in Jenkins that calls out to a Linux server, starts an Ansible Docker container that executes a playbook, and then shuts down the docker container like it never existed? ¬†Time to find out…..

For this exercise, we are going to have a Jenkins slave installed on the same Linux server that we’re going to use to launch our Ansible Docker container. ¬†Also, in our Jenkins job, we are going to configure Git as our source code repo, which is where out playbook and host files will be stored. ¬†So when the Jenkins job is executed, the playbooks\host files will be copied to the slave.

We are going to follow these steps to setup the docker piece of this puzzle.

  1. Install docker on your Jenkins slave server and then verify your version.
    • (docker -v) = Docker version 17.03.1-ce, build c6d412e
  2. Download the following Ansible Docker image. ¬†This image has an ENTRYPOINT of “ansible-playbook” and a WORKDIR of “/ansible/playbooks/. ¬†(This is key!!!)
  3. Now we need to make note of the location Jenkins downloads the Git files to on the slave.
    • Example: /home/build/ansible_git/myPlayBook.yml
    • We will use this location when starting up the docker container. ¬†(-v)
  4. Running the following command on the Jenkins slave, should then start up the Docker container that has Ansible installed, link the local folder “/home/build/ansible_git” to the container folder “/ansible/playbooks”, execute the playbook, and then shut everything down.
    • docker run –rm -it -v /home/build/ansible_git:/ansible/playbooks <image_id> myPlayBook.yml
      • –rm = cleanup
      • -it = interative and ttl
      • -v = volume (local host:container)

Docker CE vs Docker EE

Big announcement from Docker!  Looks like we have some new product names in the house.  (Docker CE & Docker EE)

  • EE = Docker Enterprise Edition (Previously¬†Docker Commercially Supported (CS))
  • CE = Docker Community Edition (Previously Docker Engine)

After you read the article above, you will notice some benefits to this new approach.

Below are some of the benefits I see.

  • A clear release cadence for both EE and CE.
    • EE will follow the stable CE releases

EECE2.png

  • New¬†time-based versioning scheme (17.03.1, 17.03.2, 18.02.1).
    • So easy to understand now!
  • Ability to separate Community (CE) updates from Docker (EE) updates .
    • Good!! – If all good features get put into CE, and not just EE!!
  • Allowing 3rd party vendors to certify their containers and plugins for Docker EE.
    • Good for Enterprises that need re-assurance!!

EECE.png

Something to point out from the above article is Docker CE and RHEL do not seem to be supported.  However, using these CentOS install instructions, I was able to get it running as a quick test.  (Fedora -> RHEL -> CentOS)  

docker2.png

However, per the documentation, RHEL and CE do not align with the support matrix below.  Also, it sounds like you could contact Docker about licensing EE for development purposes which seems to be what this article implies.

Docker.png

Docker and Jenkins

How easy is it to deploy Jenkins using Docker?  On a scale of 1 to 10, I would say something between 2 Р4.

Here are the quick steps you can follow (along with links) to help you get the job done!

  1. First and foremost, you need to get Docker installed on your server.  Here is a good link I would recommend.
  2. Next you will want to go to the Docker Store and search for Jenkins.
  3. Click on the “1” returned result
  4. Follow the instructions on the page to pull the image and run your Jenkins container
  5. I would recommend persisting your Jenkins data by specifying a volume when you start up\run the Docker Jenkins container.(-v /your/home:/var/jenkins_home)
    • -v, –volume=[host-src:]container-dest[:<options>]: Bind mount a volume