Implement GitOps for Docker

The GitOps approach is a very appealing method for the deployment of 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 that uses doesn't justify the high expenses and complex onboarding of the running Kubernetes cluster, which is 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 access to the Docker socket. Definition files received by the simplecontainer are reconciled via the Docker daemon.

You can see more at the simplecontainer site itself.

Simplecontainer
Simplecontainer manager a.k.a smr. Standalone and cluster mode, GitOps, Secrets, Reconciliation, and YAML definitions for Docker.

Installing simplecontainer

To install simplecontainer quickly:

curl -sL https://raw.githubusercontent.com/simplecontainer/smr/refs/heads/main/scripts/production/smrmgr.sh -o smrmgr
chmod +x smrmgr
sudo mv smrmgr /usr/local/bin
sudo smrmgr install
smrmgr start

The process is straightforward.

Now connect the context to the started node.

smrctl context import $(smr agent export) -y
smrctl ps
NODE                    RESOURCE                              PORTS  DEPS  ENGINE STATE      SMR STATE     

Also, a video for people who prefer it.

GitOps for Docker containers

Deploying a Docker container using the GitOps pattern is very simple. Examples are located in the GitHub repository. Many other examples can be found also.

GitHub - simplecontainer/examples: The collection of the definitions and object examples for the simple container manager.
The collection of the definitions and object examples for the simple container manager. - simplecontainer/examples
git clone https://github.com/simplecontainer/examples
cd examples

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

Inside there are:

  • tests/gitops-apps
  • tests/gitops-app-of-apps

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

prefix: simplecontainer.io/v1
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.

smrctl apply tests/gitops/apps/gitops-automatic.yaml
smrctl ps gitops
RESOURCE                   REVISION SYNCED  AUTO SYNC STATUS 
─────────────────────────────────────────────────────────────
gitops/examples/plain-auto main     deedcab true      insync 

GitOps object is present, and it is synced. So what happened here? GitOps engine will clone the remote repository and apply the pack under the /tests/minimal.

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

smrctl ps
NODE                   RESOURCE                             PORTS IMAGE STATE ENGINE STATE     SMR STATE       
───────────────────────────────────────────────────────────────────────────────────────────────────────────────
smr-development-node-1 containers/example/example-busybox-1 -     pulled      running (docker) running (1m13s) 

Objects defined in the /tests/minimal are reconciled 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
38a1ead04bf3   busybox:1.37.0   "sleep 3600"           4 minutes ago   Up 4 minutes                                                                              example-busybox-1
b0cb0ecd6b04   smr:327bf13      "/opt/smr/smr start"   4 minutes ago   Up 4 minutes   0.0.0.0:1444->1443/tcp, 127.0.0.1:2380->2379/tcp, 0.0.0.0:9213->9212/tcp   smr-development-node-2
7fe218949064   smr:327bf13      "/opt/smr/smr start"   4 minutes ago   Up 4 minutes   0.0.0.0:1443->1443/tcp, 0.0.0.0:9212->9212/tcp, 127.0.0.1:2379->2379/tcp   smr-development-node-1

We can see that simplecontainer nodes are running and busybox containers.

That's it. Implement GitOps deployment using one declarative YAML definition.

Additional resources

There are additional links on the blog of the simplecontainer regarding GitOps features.

Simplecontainer | simplecontainer.io
Simplecontainer is a lightweight orchestrator for Docker containers, capable of running on a single node or managing multiple nodes in a cluster.
GitOps without Kubernetes: Declarative, Git-driven Docker deployments with simplecontainer.io
Introduction GitOps gained traction as it was introduced into the Kubernetes ecosystem via ArgoCD. ArgoCD is the current synonym for GitOps. To enable the GitOps pattern, the platform needs to allow declarative configuration of the entity. When mentioning a platform, it can refer to any platform that serves a purpose.
Bidirectional GitOps controller for Docker with Simplecontainer
Reasoning GitOps mantra defines the Git repository as the source of the truth. GitOps controller tracks the changes on the Git repository and reconcile the state on the controlling receiving end. Usually controller implements health checking and drift detection to force the GitOps state if any manual change occurs. In