Docker container lazy loading

Lazytainer

Putting your containers to sleep

I don't really wanna do the work today


How it works

Lazy loading containers

monitor network traffic for active connections and recieved packets , if traffic looks to be idle, your container stops if it looks like you're trying to access a stopped container, it starts

Want to test it?

$ git clone https://github.com/vmorganp/Lazytainer
$ cd Lazytainer
$ docker-compose up 

Or put in your docker compose

  lazytainer:
    container_name: lazytainer
    image: ghcr.io/vmorganp/lazytainer:master
    environment:
      - PORT=81,82 # comma separated list of ports...or just the one 
      - LABEL=lazytainer # value of lazytainer.marker for other containers that lazytainer checks
      # - TIMEOUT=30 # OPTIONAL number of seconds to let container idle
      # - RXHISTLENGTH=10 # OPTIONAL number of seconds to keep rx history, uptime is calculated as first item and last item from this and must have a gap of at least $MINPACKETTHRESH
      # - MINPACKETTHRESH=10 # OPTIONAL number of packets that must be recieved to keepalive/start container 
    ports:
      - 81:81
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

  whoami1:
    container_name: whoami1
    image: containous/whoami
    command: --port 81 # make this run on the port passed through on lazytainer
    network_mode: service:lazytainer
    depends_on: 
      - lazytainer # wait for lazytainer to start before starting
    labels:
      - "lazytainer.marker=lazytainer" # required label to make it work

TODO

  • improve logging - verbosity flags
Comments
  • not working

    not working

    the install went smoothly, but even though the concept looks promising, it isn't working

    debug log: ////////////////////////////////////////////////////////////////////////////////// 60 rx packets 60 packets recieved in the last 60 seconds 0 active clients

    running on a docker host with 60 running containers..... nothing gets stopped sind 30 mins.

  • Net Able to access my application though lazytainer

    Net Able to access my application though lazytainer

    Hi,

    Im trying to use lazytainer to stop my container when not in use but im not able to access my application though lazytainer, im sure it is just a miss congiuration as im able to access without lazytainer hoping you can help :)

    Docker Compose is below

    version: "3"
    
    networks:
      gitea:
        external: false
    
    services:
      lazytainer:
        container_name: lazytainer
        hostname: lazytainer
        image: ghcr.io/vmorganp/lazytainer:1.2.0
        environment:
          - PORT=222,3000          # comma separated list of ports...or just the one 
          - LABEL=lazytainer    # value of lazytainer.marker for other containers that lazytainer checks
          - TIMEOUT=30          # OPTIONAL number of seconds to let container idle
          - MINPACKETTHRESH=10  # OPTIONAL number of packets that must be recieved to keepalive/start container 
          - POLLRATE=1          # OPTIONAL number of seconds to sleep between polls
          - VERBOSE=true        # probably set this to false unless you're debugging or doing the initial demo
        networks:
          - gitea
        ports:
          - 3000:3000
          - 222:22
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock:ro
      
      server:
        image: gitea/gitea:1.17.0
        container_name: Gitea
        hostname: gitea
        environment:
          - USER_UID=1000
          - USER_GID=1000
          - GITEA__database__DB_TYPE=mysql
          - GITEA__database__HOST=db:3306
          - GITEA__database__NAME=gitea
          - GITEA__database__USER=gitea
          - GITEA__database__PASSWD=${DB_PASSWORD}
        restart: always
        networks:
          - gitea
        volumes:
          - /srv/gitea:/data
          - /etc/timezone:/etc/timezone:ro
          - /etc/localtime:/etc/localtime:ro
        labels:
          - "lazytainer.marker=lazytainer"
          - "lazytainer.sleepMethod=stop"  # can be either "stop" or "pause", or left blank for stop
        depends_on:
          - db
          - lazytainer
    
      db:
        container_name: Gitea-db
        hostname: gitea-db
        image: linuxserver/mariadb:10.5.16-alpine
        restart: always
        environment:
          - TZ=Australia/Sydney
          - PUID=1000
          - PGID=1000
          - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
          - MYSQL_USER=gitea
          - MYSQL_PASSWORD=${DB_PASSWORD}
          - MYSQL_DATABASE=gitea
        networks:
          - gitea
        volumes:
          - /srv/gitea-db:/var/lib/mysql
        labels:
          - "lazytainer.marker=lazytainer"
          - "lazytainer.sleepMethod=stop"  # can be either "stop" or "pause", or left blank for stop
        depends_on:
         - lazytainer
    
  • fix: slim container image...

    fix: slim container image...

    This PR Depends on https://github.com/vmorganp/Lazytainer/pull/7

    • Use golang buster as build image
    • Static binary
    • Tried to slim down binary using trimpath and ldflags s w
    • Utilize buildkit with gomod and build caching
    • Ignore all except go files using .dockerignore
    • Remove unnecessary spaces
    • Slim down uncompressed container image size to 6.8MB from ~15MB

    To run and build this Dockerfile you have to set up buildkit which already comes with latest docker, Just have to enable it. It won't break anything.

    docker buildx install
    
  • exec:

    exec: "--port": executable file not found in $PATH: unknown

    Using this docker-compose as my test/example:

    --- 
    version: "3"
    services: 
      lazytainer: 
        container_name: lazytainer2
        environment: 
          - PORT=8080
          - LABEL=lazytainer
          - TIMEOUT=30
          - MINPACKETTHRESH=10
          - POLLRATE=1
          - VERBOSE=true
        image: "ghcr.io/vmorganp/lazytainer:master"
        ports: 
          - "8080:8080"
        volumes: 
          - "/var/run/docker.sock:/var/run/docker.sock:ro"
      ytdl: 
        command: --port 8080
        container_name: youtube-dl
        depends_on: 
          - lazytainer
        environment: 
          - MY_ID=dbtech
          - MY_PW=password
        image: modenaf360/youtube-dl-nas
        labels: 
          - lazytainer.marker=lazytainer
        network_mode: "service:lazytainer"
        volumes: 
          - "/home/docker/YouTube:/downfolder"
    

    I end up getting this error message:

    Pull complete ytdl 
    Pulled Container lazytainer2 
    Creating Container lazytainer2 
    Created Container youtube-dl 
    Creating Container youtube-dl 
    Created Container lazytainer2 
    Starting Container lazytainer2 
    Started Container youtube-dl 
    Starting Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "--port": executable file not found in $PATH: unknown
    

    I've tried other containers as well with similar results. Is there a reason for this and can it be fixed easily for better compatibility?

  • Client connect trigger instead of min threshold

    Client connect trigger instead of min threshold

    I got everything working great, but is there any way to make it spin up the docker container based on when a client connects or sends an http request to the port?

    I am using it with motioneye, and motioneye doesn't ever really settle down to 0 packets and is impossible to gauge the threshold correctly. It does, however, seem to register the clients connected just fine. Also, you cannot send enough traffic to motioneye to get it to trigger back on because of the login screen it uses, I think.

    TIA!

Moby Project - a collaborative project for the container ecosystem to assemble container-based systems
Moby Project - a collaborative project for the container ecosystem to assemble container-based systems

The Moby Project Moby is an open-source project created by Docker to enable and accelerate software containerization. It provides a "Lego set" of tool

Jan 8, 2023
Boxygen is a container as code framework that allows you to build container images from code

Boxygen is a container as code framework that allows you to build container images from code, allowing integration of container image builds into other tooling such as servers or CLI tooling.

Dec 13, 2021
Amazon ECS Container Agent: a component of Amazon Elastic Container Service
Amazon ECS Container Agent: a component of Amazon Elastic Container Service

Amazon ECS Container Agent The Amazon ECS Container Agent is a component of Amazon Elastic Container Service (Amazon ECS) and is responsible for manag

Dec 28, 2021
The Container Storage Interface (CSI) Driver for Fortress Block Storage This driver allows you to use Fortress Block Storage with your container orchestrator

fortress-csi The Container Storage Interface (CSI) Driver for Fortress Block Storage This driver allows you to use Fortress Block Storage with your co

Jan 23, 2022
Vilicus is an open source tool that orchestrates security scans of container images(docker/oci) and centralizes all results into a database for further analysis and metrics.
Vilicus is an open source tool that orchestrates security scans of container images(docker/oci) and centralizes all results into a database for further analysis and metrics.

Vilicus Table of Contents Overview How does it work? Architecture Development Run deployment manually Usage Example of analysis Overview Vilicus is an

Dec 6, 2022
Testcontainers is a Golang library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.

When I was working on a Zipkin PR I discovered a nice Java library called Testcontainers. It provides an easy and clean API over the go docker sdk to

Jan 7, 2023
A tool to restart a Docker container with a newer version of the image

repull A tool to restart a Docker container with a newer version of an image used by the container Often you may need to pull a newer version of an im

Nov 28, 2022
A toolbox for debugging docker container and kubernetes with web UI.
A toolbox for debugging docker container and kubernetes with web UI.

A toolbox for debugging Docker container and Kubernetes with visual web UI. You can start the debugging journey on any docker container host! You can

Oct 20, 2022
Go project to manage an ubuntu docker container
Go project to manage an ubuntu docker container

Go-docker-manager This project consist of a Go app that connects to a Docker backend, spans a Ubuntu container and shows live CPU/Memory information f

Oct 27, 2021
A docker container that can be deployed as a sidecar on any kubernetes pod to monitor PSI metrics

CgroupV2 PSI Sidecar CgroupV2 PSI Sidecar can be deployed on any kubernetes pod with access to cgroupv2 PSI metrics. About This is a docker container

Nov 23, 2021
Nanovms running in Docker x86 container for M1 Mac ARM64.

Docker Ops This project is an attempt to enable Nanos unikernels to be managed by Ops on non-intel architectures such as the Mac M1 ARM64. Unless ther

Nov 22, 2021
An little docker container to send an heartbeat to uptime kuma.

Uptime Kuma Push Service This Docker image is for sending a heartbeat to an Uptime Kuma server. Here you will find a little introduction on how to use

Apr 17, 2022
prometheus docker-container-exporter

Start with docker cd /home git clone https://github.com/sanggi-wjg/docker-container-exporter.git docker build -t dc-exporter . docker run -p 9091:90

Dec 3, 2021
Serve container tar.gz contents for docker

Serve container tar.gz contents for docker

Oct 20, 2022
Edge Orchestration project is to implement distributed computing between Docker Container enabled devices.
Edge Orchestration project is to implement distributed computing between Docker Container enabled devices.

Edge Orchestration Introduction The main purpose of Edge Orchestration project is to implement distributed computing between Docker Container enabled

Dec 17, 2021
Container actions using Golang Docker SDK

container-go Prototyping continuous integration for microservices using only Gol

Dec 28, 2021
How to get a Go / Golang app using the Gin web framework running natively on Windows Azure App Service WITHOUT using a Docker container

Go on Azure App Service View the running app -> https://go-azure-appservice.azurewebsites.net ?? This is an example repo of how to get a Go / Golang a

Nov 28, 2022
Explore Docker registries and manipulate Docker images!
Explore Docker registries and manipulate Docker images!

L/S tags Utility and API to manipulate (analyze, synchronize and aggregate) images across different Docker registries. Example invocation $ lstags alp

Nov 25, 2022
Docker-based remote code runner / 基于 Docker 的远程代码运行器
Docker-based remote code runner / 基于 Docker 的远程代码运行器

Docker-based remote code runner / 基于 Docker 的远程代码运行器

Nov 9, 2022