Code Monkey home page Code Monkey logo

lazytainer's Introduction

Lazytainer - Lazy Load Containers

Putting your containers to sleep Docker


lazytainerDemo.mp4

Quick Explanation

Monitors network traffic to containers. If there is traffic, the container runs, otherwise the container is stopped/paused. for more details check out the Configuration section.

Want to test it?

  1. Clone the project
    git clone https://github.com/vmorganp/Lazytainer
    cd Lazytainer
    
  2. Start the stack
    # if "docker compose" doesn't work, try "docker-compose"
    docker compose up
    This will create 2 containers that you can reach through a third "lazytainer" container
  3. View the running container by navigating to its web ui at http://localhost:81. You should see some information about the container
  4. Close the tab and wait until the logs say "stopped container"
  5. Navigate again to http://localhost:81, it should be a dead page
  6. Navigate to http://localhost:81 several times, enough to generate some network traffic, and it should start
  7. To clean up, run
    docker-compose down

Configuration

Note:

Lazytainer does not "automatically" start and stop all of your containers. You must apply a label to them and proxy their traffic through the Lazytainer container.

Examples

For examples of lazytainer in action, check out the Examples

Groups

Lazytainer starts and stops other containers in "groups" of one or more other containers. To assign a container to a lazytainer group, a label must be added. The label will look like this.

yourContainerThatWillSleep:
  # ... configuration omitted for brevity
  labels:
    - "lazytainer.group=<yourGroupName>"

To configure a group, add labels to the lazytainer container like this. Note that each is required to have a port(s) specified. These ports must also be forwarded on the lazytainer container

lazytainer:
  # ... configuration omitted for brevity
  ports:
    - 81:81 # used by group1 and group2
    - 82:82 # used by group2
  labels:
    # Configuration items are formatted like this
    - "lazytainer.group.<yourGroupName>.<property>=value"
    # configuration for group 1
    - "lazytainer.group.group1.ports=81"
    # configuration for group 2
    - "lazytainer.group.group2.ports=81,82"

Group properties that can be changed include:

Name description required default
ports Network ports associated with a group, can be comma separated. Should be the INTERNAL port, not the EXPOSED port. ex: service running on 8080 but exposed on 80 should have port set to 8080 Yes n/a
inactiveTimeout Time (seconds) before container is stopped when there is insufficient network activity No 30
minPacketThreshold Minimum count of network packets for container to be on No 30
pollRate How frequently (seconds) to check network activity No 30
sleepMethod How to put the container to sleep. Can be stop or pause No stop
netInterface Network interface to listen on No eth0

Additional Configuration

Verbose Logging

If you would like more verbose logging, you can apply the environment variable VERBOSE=true to lazytainer like so

lazytainer:
  # ... configuration omitted for brevity
  environment:
    - VERBOSE=true

Volumes

If using lazytainer, you MUST provide the following volume to lazytainer

lazytainer:
  # ... configuration omitted for brevity
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro

lazytainer's People

Contributors

vmorganp avatar dependabot[bot] avatar jackbailey avatar pratikbin avatar technotiger avatar heisenberg2980 avatar calrock27 avatar d3lity avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.