Personal Programming Notes

To err is human; to debug, divine.

Docker-in-Docker vs Docker-out-of-Docker

In this post, we look into two different approaches to solving the problem of building/pushing Docker images from a containerized Jenkins system. From that understanding, we will discuss the pros and cons of each approach in production Continuous Integration (CI) systems and how one should be used in practice.

Load Groovy Script in Jenkins Pipeline

In this post, we look into loading and reusing independent Groovy scripts for more modular and testable Jenkins pipeline. An example with Scripted Pipeline is provided although it is also applicable to newer Declarative Pipeline with minor modifications. Keep in mind that Jenkins Shared Libraries is the more scalable alternative to run and reuse custom Groovy scripts in Jenkins pipeline.

Updating Jenkins Pipeline Shared Libraries

When you have multiple Pipeline jobs, you often want to share some parts of the Jenkinsfiles between them to keep Jenkinfiles DRY. A very common use case is that you have many projects that are built in the similar way, such as Nexus authentication step in Gradle build. One way is to use Workflow plugin. Comprehensive user documentation can be found in this section of Jenkins handbook.

In the following sections, we review a couple older, but not necessarily worse, ways of updating shared Groovy code which are still used in some Jenkins system.

Docker: Files Not Found in Docker Container

In this post, we look into a perplexing issue that happens often when we try to extend an offical image. In summary, there is currently no way to add additional content into VOLUME directory in a trivial way. If you unknowingly adds files into a folder that has been used as a VOLUME mount point in a Docker image or one of its base images, the files cannot be found for seemingly no reason.

Docker: Copy File Into a Container

In this blog post, we have a running Docker container or a running pod in Kubernetes cluster. We want to add some files into the running containers to fix some issue, verify, and commit the changes.

Docker: Root User in a Pod

In the following scenario, we have some pod running in Kubernetes cluster.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
tdongsi-mac:kubernetes tdongsi$ kubectl --kubeconfig kubeconfig describe pod jenkins
Name:             jenkins
Namespace:            default
Image(s):         docker.registry.company.net/tdongsi/jenkins:2.23
Node:             kube-worker-1/10.252.158.72
Start Time:           Tue, 24 Jan 2017 16:57:47 -0800
Labels:               name=jenkins
Status:               Running
Reason:
Message:
IP:               172.17.27.3
Replication Controllers:  <none>
Containers:
  jenkins:
    Container ID: docker://943d6e55038804c8
    Image:        docker.registry.company.net/tdongsi/jenkins:2.23
    Image ID:     docker://242c1836544e5ca31616
    State:        Running
      Started:        Tue, 24 Jan 2017 16:57:48 -0800
    Ready:        True
    Restart Count:    0
    Environment Variables:
Conditions:
  Type        Status
  Ready   True
Volumes:
  jenkins-data:
    Type: HostPath (bare host directory volume)
    Path: /jdata
No events. 

For troubleshooting purposes, we sometimes need to enter the container or execute some commands with root privilege. Sometimes, we simply cannot sudo or have the root password.