lazytainer

repository·master·Indexed 20 days ago

https://github.com/vmorganp/lazytainer

A tool for lazy loading Docker containers by monitoring network traffic. It automatically stops or pauses containers when inactive and wakes them up when network traffic is detected on specified ports to conserve system resources. Configuration is managed via Docker labels on target containers and the lazytainer service itself, requiring access to the Docker socket.

Tokens
4K
Snippets
19
Records
25
Agent score
72%

What's inside lazytainer

  1. How Lazytainer works

    master

    Lazytainer is a tool that monitors network traffic to containers. If there is active network traffic, the container runs; if there is no traffic, the container is stopped or paused.

    To use Lazytainer, you cannot simply run containers normally. You must:

    1. Apply specific labels to the target containers to assign them to a group.
    2. Proxy all traffic for those containers through the Lazytainer container.
  2. Connect the ZeroTier container to a network

    master

    After starting the containers, you must manually join the ZeroTier network from within the container:

    1. Access the container shell: docker exec -it zerotier /bin/sh
    2. Join your specific network using the ZeroTier CLI: zerotier-cli join <yourZeroTierNetworkIDHere>
    3. Verify the response is 200 join OK.
    4. Important: You must authorize the new device in your ZeroTier dashboard.
    5. Identify the ZeroTier interface name by running ifconfig. Look for an interface name that is NOT eth0 or lo (e.g., ztukuxxqii).
    6. Exit the container shell.
    docker exec -it zerotier /bin/sh
    zerotier-cli join <yourZeroTierNetworkIDHere>
    ifconfig
    exit
  3. Run the Lazy Load Docker Minecraft Server example

    master

    To test the lazy loading functionality using the Minecraft server example, clone the repository, navigate to the specific example directory, and use docker-compose to start the services.

    Note: If docker compose is not recognized on your system, try using docker-compose instead.

    git clone https://github.com/vmorganp/Lazytainer
    cd Lazytainer/examples/minecraft
    docker-compose up
  4. Deploy the Satisfactory Server example

    master

    To run the Satisfactory server example using Lazytainer, clone the repository, navigate to the specific example directory, and use Docker Compose to start the stack.

    If docker compose is not recognized on your system, use docker-compose instead.

    git clone https://github.com/vmorganp/Lazytainer
    cd Lazytainer/examples/satisfactory
    docker compose up
  5. Configure the INTERFACE for Lazytainer over ZeroTier

    master

    To ensure Lazytainer communicates over the ZeroTier network rather than the standard Docker bridge, you must update your configuration with the specific ZeroTier interface name discovered in the previous step.

    1. Locate the INTERFACE setting in your configuration file.
    2. Set INTERFACE to the name found via ifconfig (e.g., ztukuxxqii).
    3. Restart the containers using docker compose up to apply the changes.

    To run the configuration in the background after verifying it works, use the detached flag: docker compose up -d

    docker compose up -d
  6. Test Lazytainer with a local setup

    master

    You can test the functionality by cloning the repository and running the provided docker-compose stack:

    1. Clone and enter the directory:
      git clone https://github.com/vmorganp/Lazytainer
      cd Lazytainer
    2. Start the stack:
      docker compose up
    3. Access the web UI at http://localhost:81 to see container information.
    4. Close the tab and wait for the logs to indicate "stopped container".
    5. Refreshing http://localhost:81 should result in a dead page.
    6. Generate traffic by navigating to http://localhost:81 several times; the container should start automatically.
    7. Clean up the environment:
      docker-compose down
    git clone https://github.com/vmorganp/Lazytainer
    cd Lazytainer
    docker compose up
    # ... test traffic ...
    docker-compose down
  7. Assign containers to Lazytainer groups

    master

    To make a container eligible for lazy loading, you must assign it to a group using a label. The label format is lazytainer.group=<yourGroupName>.

    yourContainerThatWillSleep:
      labels:
        - "lazytainer.group=<yourGroupName>"
  8. Run Lazytainer over ZeroTier using Docker Compose

    master

    To use Lazytainer over a ZeroTier network, use the zyclonite/zerotier Docker image within a Docker Compose setup.

    1. Copy the docker-compose.yml file from the examples/zerotier/ directory into your target directory.
    2. Configure the values in the YAML file to match your requirements.
    3. Run docker compose up to start the containers.
    docker compose up
  9. Required volume for Lazytainer

    master

    To function correctly, Lazytainer MUST have access to the Docker socket. You must provide the following volume mapping in your configuration:

    lazytainer:
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock:ro
  10. Configure Lazytainer groups

    master

    Groups are configured by adding labels to the lazytainer container itself. Each group configuration must include the ports property. These ports must also be forwarded on the lazytainer container.

    Configuration follows the pattern: lazytainer.group.<yourGroupName>.<property>=value.

    lazytainer:
      ports:
        - 81:81
        - 82:82
      labels:
        - "lazytainer.group.group1.ports=81"
        - "lazytainer.group.group2.ports=81,82"
  11. Configure Lazytainer environment variables

    master

    You can control logging and network protocols using environment variables on the lazytainer container:

    • VERBOSE=true: Enables more verbose logging.
    • IPV6_DISABLED=true: Disables IPv6.
    • IPV4_DISABLED=true: Disables IPv4.
    lazytainer:
      environment:
        - VERBOSE=true
        - IPV6_DISABLED=true
        - IPV4_DISABLED=true