Self-Hosting Image Optimization: A Guide to Mochify-Lite on Docker
Want to do your own image compression without relying on third-party services? This guide walks you through setting up Mochify-Lite, a powerful open-source image optimization tool, on Docker. Perfect for developers and privacy-conscious users who want full control over their image processing.
What's in This Guide
Pulling the Image from Docker Hub
Setting up Mochify-Lite is straightforward because it is containerized. Since it is hosted on Docker Hub, you can pull the image and have the engine running in seconds.
To run the engine with optimal security and performance settings, use the following command. This configuration runs the container in the background, maps the necessary ports, and secures the environment:
docker run -d --name mochify-lite -p 5555:5555 --read-only --tmpfs /app/temp_ram_buffer:rw,size=64m,mode=1777 --security-opt=no-new-privileges mochify/mochify-lite:latestUnderstanding the Configuration
If you are new to Docker, here is a quick breakdown of what these flags are doing:
-d:Runs the container in "detached" mode (in the background).-p 5555:5555:Maps port 5555 of the container to port 5555 on your local machine. This is the gateway to the compression API.--read-only:A security best practice that makes the container's root filesystem immutable, preventing accidental or malicious changes.--tmpfs:Since the filesystem is read-only, this creates a small, fast 64MB buffer in RAM for the engine to process images temporarily.--security-opt=no-new-privileges:Prevents the container processes from gaining additional privileges, adding an extra layer of security.
Once the command finishes, your local image compression engine is live and ready to receive requests at http://localhost:5555. Further example configuration can be found on GitHub.
Using the API for Image Compression
Once your container is running, you have a high-performance compression engine sitting at the ready. Unlike SaaS tools that force you through a web interface, Mochify-Lite exposes a clean REST API. This means you can integrate it into your build scripts, local workflows, or even a right-click "Quick Action" on your desktop.
The engine uses libjpeg-turbo and libpng under the hood, industry-standard libraries known for their balance of high speed and surgical precision.
How to "Squish" an Image
The primary endpoint is /v1/squish. It accepts standard image formats (JPEG and PNG) up to 10MB in size. To optimize an image, you simply POST the binary data to your local endpoint:
curl -X POST "http://localhost:5555/v1/squish" -H "Content-Type: image/jpeg" --data-binary "@mochi.jpg" --output mochi_optimized.jpgLeveling Up: Mochify vs. Mochify-Lite
While Mochify-Lite is a fantastic "drop-in" tool for standard JPEG and PNG tasks, the full Mochify engine is designed for developers who need to support the cutting edge of web performance.
If your project requires next-gen formats like AVIF or the ultra-efficient JPEG XL, you'll want to look at the full engine. Here is how they stack up:
| Feature | Mochify-Lite | Mochify (Full) |
|---|---|---|
| JPEG Engine | libjpeg-turbo (Speed) | Jpegli (Highest Quality/Ratio) |
| Max File Size | 10MB | 20MB |
| Input Formats | JPG, PNG | JPG, PNG, HEIC, AVIF, WebP |
| Output Formats | JPG, PNG | JPG, PNG, AVIF, WebP, JXL |
| Use Case | Quick local scripts & legacy apps | Production-grade asset pipelines |
Why the Full Engine Matters: Jpegli and JXL
The most significant difference in the full version is the switch to Jpegli. Developed by Google, Jpegli is a newer library that produces JPEGs that are significantly more compressed (often 30% smaller) than standard libraries while remaining 100% compatible with existing browsers and viewers.
Furthermore, the full engine unlocks JPEG XL (JXL) support—the format many believe to be the true successor to JPEG, offering superior lossless compression and better responsiveness.
Ready to convert your images?
Try Mochify's zero-retention WebP and AVIF converters - no accounts, no plugins, no stored files. Process in-memory with C++ engine speed, then upload directly to your site or marketplace.
Start Optimizing