Implement GitOps with Docker

The GitOps approach is a very appealing method for the deployment of the applications. It provides a clean way to maintain configuration, versions, and deployment using git as a source of the truth. Docker itself doesn't provide a method for achieving this.

When you use Docker Compose or Docker Swarm you need to apply definition files yourself.

Doing docker-compose limits the usage most often to the developer's local environment since maintaining it for complex projects is a little bit trickier.

Inspired by Kubernetes and ArgoCD, simplecontainer provides the functionalities of declarative definitions, reconciliation, and GitOps for the containers currently only running under the Docker daemon.

Why simplecontainer?

Often deploying internal company tools, simple blogs, single host applications and other software which uses doesn't justify the high expenses and complex onboard of the running Kubernetes cluster are stuck to some variations of glue scripts to build and deploy software on the virtual machines.

The on-prem software for maintenance of the deployments of the container is available but offerings are limited since no one cares about those.

The simplecontainer provides a declarative way of defining:

  • Containers
  • GitOps
  • Network
  • Resource
  • Configuration
  • And other resources..

The simplecontainer runs as a container itself with given access to the Docker socket. Definition files received by the simplecontainer are reconciled to the Docker daemon via the socket itself.

You can see more at the simplecontainer site itself.

Simplecontainer
Simple container manager. Key store, GitOps, Templating, Reconciliation, and Kubernetes-Alike experience on Docker.

Installing simplecontainer

To install simplecontainer follow the Quick Start tutorial:

Quick start
This is a quick start tutorial for getting a simple container up and running. Installation of the agent To start using simplecontainer, first run it to generate a project and build a configuration file. Note: This is example for the localhost. If domain is example.com running on the virtual

Process is straightforward, just follow the instructions in the article.

GitOps for Docker containers

Following the examples in the https://github.com/simplecontainer/examples/tree/main/tests/gitops we will demonstrate how to implement GitOps design using only Docker as the platform.

git clone https://github.com/simplecontainer/examples
cd examples

Now there are multiple directories. Let's inspect /tests/gitops/apps

Inside there are:

  • apps/gitops-plain.yaml
  • apps/gitops-auto.yaml

Let's inspect the file apps/gitops-automatic.yaml.

kind: gitops
meta:
  group: examples
  name: plain-auto
spec:
  repoURL: "https://github.com/simplecontainer/examples"
  revision: "main"
  automaticSync: true
  directoryPath: "/tests/minimal"

tests/gitops/apps/gitops-automatic.yaml

Applying this file, simplecontainer will receive the GitOps object and will reconcile the definition to the state defined.

smr apply tests/gitops/apps/gitops-automatic.yaml
smr gitops list
GROUP     NAME          REPOSITORY                                             REVISION  SYNCED        AUTO   STATE    
examples  plain-auto    https://github.com/simplecontainer/examples (cb849c3)  main      cb849c3       true   InSync   

As we can see there is GitOps object and smr CLI is printing out the state of it.

Running the smr ps will print out the containers which are managed by the simplecontainer and state of those.

smr ps
GROUP    NAME     DOCKER NAME        IMAGE           IP  PORTS  DEPS  DOCKER STATE  SMR STATE         
example  busybox  example-busybox-1  busybox:latest                   running       running (24m49s)  
example  busybox  example-busybox-2  busybox:latest                   running       running (24m49s) 

Objects defined in the /tests/minimal are reconciled the definition to the Docker daemon, since busybox containers are running.

If you execute docker ps on the same host where simplecontainer is running you will get the state of the running containers.

docker ps
CONTAINER ID   IMAGE            COMMAND                CREATED             STATUS             PORTS                    NAMES
509e02877b72   busybox:latest   "sleep 3600"           26 minutes ago      Up 26 minutes                               example-busybox-2
a17f9f7b8761   busybox:latest   "sleep 3600"           26 minutes ago      Up 26 minutes                               example-busybox-1
9387c7b303f2   smr:137fdf4      "/opt/smr/smr start"   About an hour ago   Up About an hour   0.0.0.0:1443->1443/tcp   smr-agent

We can see that simplecontainer is running and busybox containers.

It is pretty easy to implement gitops apporach for the deployment of the Docker containers and other accompanying objects - which you can read more about those objects at the simplecontainer.qdnqn.com.