Sign inSign up

comanderanch/dind-orchestrator

By comanderanch

•Updated over 1 year ago

Image
0

286

comanderanch/dind-orchestrator repository overview

⁠Docker-in-Docker (DinD) Orchestrator

A Docker-in-Docker (DinD) Orchestrator designed to run Docker Compose inside a container and dynamically generate services. This setup enables the ability to define services within Docker, allowing for extensible, scalable, and self-contained container orchestration.


⁠Features:

  • Docker-in-Docker (DinD): Run containers inside a container.
  • Dynamic Compose Generation: Uses a C++ program to generate a docker-compose.yml file dynamically.
  • Persistent Volumes: Ensures configuration and data persist across container restarts.
  • Service Stacking: Ability to define services inside docker-compose.yml and scale them dynamically.
  • Port Mapping & Reverse Proxy: Use Nginx (optional) to expose services.

⁠Getting Started

⁠1. Pull the Prebuilt Image from Docker Hub
docker pull comanderanch/dind-orchestrator:latest
⁠2. Create Required Directories on Host

Before running the container, set up directories for volume mappings to persist configurations.

mkdir -p ~/cpp-orchestrator/generated_files
mkdir -p ~/cpp-orchestrator/config
⁠3. Run the Container with Docker-in-Docker
docker run -d --privileged --name dind-runner \
  -p 8080:80 \
  -v ~/cpp-orchestrator/generated_files:/app/generated_files \
  -v /var/run/docker.sock:/var/run/docker.sock \
  comanderanch/dind-orchestrator

Note: --privileged is required for DinD to function properly.


⁠Volume Mapping

To persist generated compose files and configuration files, the following volume mappings are used:

Host PathContainer PathPurpose
~/cpp-orchestrator/generated_files/app/generated_filesStores generated docker-compose.yml
/var/run/docker.sock/var/run/docker.sockAllows Docker commands inside the container

⁠Running Services Inside the DinD Container

Once inside the dind-runner container:

  1. Access the container:
docker exec -it dind-runner sh
  1. Navigate to the generated compose file:
cd /app/generated_files
  1. Run the generated services:
docker-compose up -d

This will start all services defined in docker-compose.yml dynamically generated inside the container.


⁠Persisting Services (Auto-Restart)

By default, containers may exit after execution. To keep services running indefinitely, update the docker-compose.yml:

version: '3.8'
services:
  ubuntu-node:
    image: ubuntu:22.04
    command: ["sleep", "infinity"]
    restart: always

Then, re-run:

docker-compose up -d

⁠Adding More Services Inside DinD

To add more services dynamically:

  1. Modify docker-compose.yml inside the container (/app/generated_files/docker-compose.yml)
  2. Add a new service block:
  nginx:
    image: nginx:latest
    ports:
      - "8081:80"
    volumes:
      - ./config/nginx.conf:/etc/nginx/nginx.conf:ro
  1. Restart the services:
docker-compose up -d

⁠Load Balancing & Service Stacking

Using Nginx or another reverse proxy inside DinD, services can be stacked and routed dynamically.

  • Forward all traffic to one entry point (8080) and internally distribute between services.
  • Modify nginx.conf to route services correctly.
⁠Example Reverse Proxy (Nginx Config)
server {
    listen 80;

    location /service1 {
        proxy_pass http://service1:8000;
    }

    location /service2 {
        proxy_pass http://service2:9000;
    }
}

Use the docker-compose.yml inside dind-runner to define the services and forward traffic accordingly.


⁠Pushing to Docker Hub

Once the image is working as expected:

docker tag dind-orchestrator comanderanch/dind-orchestrator:latest

docker push comanderanch/dind-orchestrator:latest

⁠Future Enhancements

  • Implement a script to automatically start services on dind-runner container start.
  • Enable external database and persistent storage options.
  • Integrate logging and monitoring using Prometheus & Grafana.

⁠Conclusion

With Docker-in-Docker (DinD) Orchestrator, you can define and stack services dynamically inside a container.

šŸ’” This setup allows for multi-container orchestration without needing a separate VM or external host management.

Feel free to fork, modify, and contribute to this setup!


⁠Maintained by Comanderanch @ Hack-Shak⁠ šŸš€

I am a beginner at all of this. And I owe the Desire and means to learn and try to do something great too help in the open source community to my nephew and best freind <thehomebuiscuit> thank you b the hack-shak forever!!!

Tag summary

Content type

Image

Digest

sha256:efcc1e3c9…

Size

288 MB

Last updated

over 1 year ago

docker pull comanderanch/dind-orchestrator