  Edge and Fog computing paradigms overcome the limitations of Cloud-centric
execution for different latency-sensitive Internet of Things (IoT) applications
by offering computing resources closer to the data sources. In both paradigms,
single-board small computers like Raspberry Pis (RPis) are widely used as the
computing nodes. RPis are usually equipped with processors having moderate
speed and provide supports for peripheral interfacing and networking. These
features make RPis well-suited to deal with IoT-driven operations such as data
sensing, analysis and actuation. However, RPis are constrained in facilitating
multi-tenancy and resource sharing. The management of RPi-based computing and
peripheral resources through centralized entities further degrades their
performance and service quality significantly. To address these issues, a
framework, named \textit{Con-Pi} is proposed in this work. It exploits the
concept of containerization and harnesses Docker containers to run IoT
applications as microservices on RPis. Moreover, Con-Pi operates in a
distributed manner across multiple RPis and enables them to share resources.
The software system of the proposed framework also provides a scope to
integrate different application, resource and energy management policies for
Edge and Fog computing. The performance of the proposed framework is compared
with the state-of-the-art frameworks by means of real-world experiments. The
experimental results evident that Con-Pi outperforms others in enhancing
response time and managing energy usage and computing resources through
distributed offloading. Additionally, we have developed a pest bird deterrent
system using Con-Pi to demonstrate its suitability in developing practical
solutions for various IoT-enabled use cases including smart agriculture.
