<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: ...</title>
    <description>The latest articles on Forem by ... (@codebrowse).</description>
    <link>https://forem.com/codebrowse</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1342711%2Fb023b80e-98af-412c-b8ef-a87ed7a87232.png</url>
      <title>Forem: ...</title>
      <link>https://forem.com/codebrowse</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codebrowse"/>
    <language>en</language>
    <item>
      <title>Case Study: Building a Scalable CRUD Application with Quarkus</title>
      <dc:creator>...</dc:creator>
      <pubDate>Sun, 23 Feb 2025 09:33:49 +0000</pubDate>
      <link>https://forem.com/codebrowse/case-study-building-a-scalable-crud-application-with-quarkus-35cn</link>
      <guid>https://forem.com/codebrowse/case-study-building-a-scalable-crud-application-with-quarkus-35cn</guid>
      <description>&lt;h2&gt;
  
  
  1. Overview
&lt;/h2&gt;

&lt;p&gt;This case study explores the development of a &lt;em&gt;Person Management System&lt;/em&gt; using Quarkus, a Kubernetes-native Java framework optimized for cloud environments. The application demonstrates CRUD operations (Create, Read, Update, Delete) with a MySQL database, leveraging Quarkus' efficiency, developer-friendly tooling, and native compilation capabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Project Objectives
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;    Build a performant REST API for managing Person entities.&lt;/li&gt;
&lt;li&gt;    Utilize Quarkus' live coding features for rapid development.&lt;/li&gt;
&lt;li&gt;    Demonstrate integration with Hibernate ORM/Panache for simplified database interactions.&lt;/li&gt;
&lt;li&gt;    Package the application as a lightweight JAR and native executable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Technical Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Architecture Diagram&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nln3k5vdu6ucp9o3cmi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nln3k5vdu6ucp9o3cmi.png" alt="Architecture Diagram" width="800" height="684"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Components:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MySQL Database&lt;/strong&gt;: Stores &lt;code&gt;Person&lt;/code&gt; records.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hibernate ORM/Panache&lt;/strong&gt;: Manages persistence layer with active record pattern.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RESTEasy&lt;/strong&gt;: Implements JAX-RS endpoints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SmallRye OpenAPI&lt;/strong&gt;: Auto-generates OpenAPI documentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Implementation Highlights
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Data Model
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Entity  
@Table(name = "Person")  
public class Person {  
    @Id  
    @GeneratedValue(strategy = GenerationType.IDENTITY)  
    private Long id;  
    private String name;  
    // Getters/Setters  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Uses Hibernate annotations for ORM mapping with MySQL auto-increment IDs.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2 Repository Layer
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@ApplicationScoped  
public class PersonRepository implements PanacheRepository&amp;lt;Person&amp;gt; {  
    Person findByName(String name) {  
        return find("name", name).firstResult();  
    }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Extends PanacheRepository for out-of-the-box CRUD methods while adding custom queries.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4.3 REST Service
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Path("/persons")  
@ApplicationScoped  
public class PersonService {  
    @Inject PersonRepository personRepository;  

    @GET  
    public Response getAllPersons() {  
        return Response.ok(personRepository.listAll()).build();  
    }  

    @POST  
    @Transactional  
    public Response savePerson(Person person) {  
        personRepository.persist(person);  
        return Response.ok(person.getName() + " saved").build();  
    }  
    // PUT, DELETE methods omitted for brevity  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Key Features:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Transaction management via &lt;code&gt;@Transactional&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;    JAX-RS annotations for endpoint definition&lt;/li&gt;
&lt;li&gt;    JSON serialization/deserialization handled automatically&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4.4 Database Configuration
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;application.properties&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;quarkus.datasource.db-kind=mysql  
quarkus.datasource.jdbc.url=jdbc:mysql://localhost:3306/mydb  
quarkus.hibernate-orm.database.generation=update  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Configures MySQL connection and automatic schema updates.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Development Workflow
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5.1 Live Coding
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./mvnw clean compile quarkus:dev  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;    Code changes reflected instantly without restart&lt;/li&gt;
&lt;li&gt;    Access Dev UI at &lt;code&gt;http://localhost:8080/q/dev&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5.2 Testing Endpoints
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create Person  
curl -X POST -H "Content-Type: application/json" \  
  -d '{"name":"John Doe"}' http://localhost:8080/persons  

# Retrieve All  
curl http://localhost:8080/persons  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.3 Packaging
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Standard JAR  
./mvnw package  

# Native Executable (GraalVM)  
./mvnw package -Dnative  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Result:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Uber-JAR size: ~15MB&lt;/li&gt;
&lt;li&gt;    Native executable startup time: ~0.01s&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Challenges &amp;amp; Solutions
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Challenge&lt;/th&gt;
&lt;th&gt;Quarkus Solution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Database schema management&lt;/td&gt;
&lt;td&gt;&lt;code&gt;quarkus.hibernate-orm.database.generation=update&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Boilerplate CRUD code&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;PanacheRepository&lt;/code&gt; base class&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Native compilation issues&lt;/td&gt;
&lt;td&gt;Containerized builds via &lt;code&gt;-Dquarkus.native.container-build=true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  7. Results &amp;amp; Metrics
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;API Response Times (10k requests)&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JVM Mode: Avg 12ms&lt;/li&gt;
&lt;li&gt;Native Mode: Avg 8ms&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Memory Usage&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JVM Heap: ~120MB&lt;/li&gt;
&lt;li&gt;Native: ~45MB RSS&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Conclusion
&lt;/h2&gt;

&lt;p&gt;This project demonstrates Quarkus' strengths in building modern Java applications:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Developer Productivity&lt;/strong&gt;: Live reload, Dev UI, and simplified Hibernate configuration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Subsecond startup times and low memory footprint in native mode.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Readiness&lt;/strong&gt;: Container-friendly packaging and native Kubernetes integration.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Future Enhancements:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add frontend with Quarkus Qute templating&lt;/li&gt;
&lt;li&gt;Implement reactive endpoints with Mutiny&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Quarkus Documentation&lt;/strong&gt;: &lt;a href="//quarkus.io/guides"&gt;quarkus.io/guides&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This case study demonstrates how Quarkus enables developers to build cloud-native applications that combine traditional Java strengths with modern runtime efficiencies.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>quarkus</category>
      <category>java</category>
      <category>cloudnative</category>
      <category>backend</category>
    </item>
    <item>
      <title>Optimize Docker Performance: Strategies for Enhancing Image Creation and Runtime Container Management</title>
      <dc:creator>...</dc:creator>
      <pubDate>Sun, 26 May 2024 05:23:11 +0000</pubDate>
      <link>https://forem.com/codebrowse/strategies-for-optimizing-docker-image-creation-and-runtime-container-management-j1b</link>
      <guid>https://forem.com/codebrowse/strategies-for-optimizing-docker-image-creation-and-runtime-container-management-j1b</guid>
      <description>&lt;p&gt;Docker has become a crucial tool for creating, deploying, and managing containerized applications. However, as applications grow in complexity, so do their Docker images and runtime environments. Efficiently managing these Docker images and containers is crucial for maintaining performance, reducing disk usage, and ensuring smooth operations. Let us look at some strategies for optimizing Docker image creation and runtime container management. Additionally, let us cover best practices. By following these strategies and techniques, you can achieve a more efficient and manageable Docker setup, ultimately leading to improved application performance and resource utilization.&lt;/p&gt;

&lt;p&gt;To optimize Docker image creation, you can use tools and techniques such as Docker Slim, Zstandard (Zstd) compression, and Docker Squash. These approaches help reduce image size and improve performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Choose a Smaller Base Image
&lt;/h2&gt;

&lt;p&gt;Use lightweight base images such as &lt;em&gt;alpine&lt;/em&gt; whenever possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Docker Slim
&lt;/h2&gt;

&lt;p&gt;Docker Slim reduces the size of Docker images by stripping away unnecessary files and dependencies, leading to smaller, more secure images. &lt;a href="https://github.com/slimtoolkit/slim#downloads" rel="noopener noreferrer"&gt;Click here&lt;/a&gt; to know more about DockerSlim&lt;br&gt;
&lt;strong&gt;Installation:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;curl -sL https://raw.githubusercontent.com/slimtoolkit/slim/master/scripts/install-slim.sh | sudo -E bash -&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;slim build --tag=myimage.slim myimage:latest&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Zstandard (Zstd) Compression
&lt;/h2&gt;

&lt;p&gt;Zstd offers high compression ratios and fast decompression, making it suitable for compressing Docker images.&lt;br&gt;
&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Compress Docker Image&lt;br&gt;
&lt;code&gt;docker save myimage:latest | zstd -o myimage.tar.zst&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Load Compressed Docker Image&lt;br&gt;
&lt;code&gt;zstd -d myimage.tar.zst -o myimage.tar&lt;br&gt;
docker load &amp;lt; myimage.tar&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you encounter difficulties with Zstd compression for your image compression, consider using &lt;a href="https://linuxhandbook.com/pigz/" rel="noopener noreferrer"&gt;&lt;em&gt;pigz&lt;/em&gt;&lt;/a&gt; instead.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Docker Squash
&lt;/h2&gt;

&lt;p&gt;Docker Squash reduces the number of layers in a Docker image, which can simplify the image structure and reduce its size.&lt;br&gt;
&lt;strong&gt;Installation:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;pip install docker-squash&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker-squash -t myimage:squashed myimage:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For optimizing docker containers, combine strategies for managing container runtime disk usage, cleaning up unused Docker objects, and optimizing image creation and performance.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Persistent Storage Volumes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bind Mounts:&lt;/strong&gt;&lt;br&gt;
Bind mounts allow you to mount a directory from the host machine into the container. This is useful for persistent data that needs to exist outside the container's lifecycle.&lt;br&gt;
&lt;code&gt;docker run -v /host/path:/container/path myimage&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Named Volumes:&lt;/strong&gt;&lt;br&gt;
Named volumes are managed by Docker and can be used to persist data. These volumes are not tied to any specific directory on the host machine.&lt;br&gt;
&lt;code&gt;docker volume create myvolume&lt;br&gt;
docker run -v myvolume:/container/path myimage&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Clean Up After Operations
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Log Rotation:&lt;/strong&gt;&lt;br&gt;
Log rotation helps manage log files by limiting their size and the number of log files retained, preventing logs from consuming excessive disk space.&lt;br&gt;
&lt;code&gt;docker run --log-opt max-size=10m --log-opt max-file=3 myimage&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temporary File Cleanup:&lt;/strong&gt;&lt;br&gt;
Remove temporary files generated during container operations to prevent them from consuming disk space. Use a cleanup script or application logic to delete temporary files after use.&lt;br&gt;
&lt;code&gt;# In a Dockerfile&lt;br&gt;
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y mypackage &amp;amp;&amp;amp; rm -rf /var/lib/apt/lists/*&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regular Cleanup with Cron:&lt;/strong&gt;&lt;br&gt;
Schedule regular cleanup tasks to remove unnecessary files and manage disk usage effectively. Use cron jobs or similar tools to automate periodic cleanup.&lt;br&gt;
&lt;code&gt;# In a containerized application&lt;br&gt;
crontab -l | { cat; echo "0 * * * * rm -rf /path/to/temp/files/*"; } | crontab -&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Optimize Application Behavior
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;In-Memory Processing:&lt;/strong&gt;&lt;br&gt;
Use in-memory processing to minimize disk I/O operations, which can help reduce disk usage and improve performance. Process data in memory instead of writing to disk when feasible.&lt;br&gt;
&lt;code&gt;# Example in Python&lt;br&gt;
data = process_data_in_memory()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Efficient Data Handling:&lt;/strong&gt;&lt;br&gt;
Optimize how your application reads and writes data to avoid redundant operations and reduce disk usage. Ensure efficient data handling by writing data only when necessary.&lt;br&gt;
&lt;code&gt;with open('file.txt', 'w') as file:&lt;br&gt;
    file.write(data)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Temporary Storage:&lt;/strong&gt;&lt;br&gt;
For temporary data that doesn't need to be persisted, use temporary filesystems like tmpfs to store data in memory. Mount a tmpfs volume for temporary data storage.&lt;br&gt;
&lt;code&gt;docker run --mount type=tmpfs,destination=/path/to/tmpfs myimage&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Prune Unused Docker Objects
&lt;/h2&gt;

&lt;p&gt;To manage disk space and maintain a clean Docker environment, you can prune unused Docker objects such as images, containers, volumes, and networks. Docker provides commands to prune each of these object types, helping you free up disk space and keep your Docker environment tidy.&lt;br&gt;
&lt;strong&gt;Prune Images:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker image prune -a -f&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prune Containers:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker container prune -f&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prune Volumes:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker volume prune -f&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prune Networks:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker network prune -f&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prune All Unused Objects:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker system prune -a -f --volumes&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  5. Automate Pruning with a Script
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Pruning Script:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Prune unused images
docker image prune -a -f

# Prune stopped containers
docker container prune -f

# Prune unused volumes
docker volume prune -f

# Prune unused networks
docker network prune -f

# Optionally, prune all unused objects
# docker system prune -a -f --volumes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Scheduling with Cron:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;crontab -e&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following line to run the script daily at midnight:&lt;br&gt;
&lt;code&gt;0 0 * * * /path/to/your/script.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Example Dockerfile Incorporating Best Practices&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Dockerfile
FROM ubuntu:20.04

# Install necessary packages
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y python3 &amp;amp;&amp;amp; rm -rf /var/lib/apt/lists/*

# Copy application code
COPY . /app
WORKDIR /app

# Set up a volume for persistent data
VOLUME /app/data

# Use tmpfs for temporary files
RUN mkdir -p /tmp/data
VOLUME /tmp/data

# Cleanup script for temporary files
RUN echo "0 * * * * root rm -rf /tmp/data/*" &amp;gt;&amp;gt; /etc/crontab

# Run the application
CMD ["python3", "app.py"]

**Docker Run Command**
docker run -d --name myapp \
  -v appdata:/app/data \
  --mount type=tmpfs,destination=/tmp/data \
  --log-opt max-size=10m --log-opt max-file=3 \
  myimage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By following these strategies and best practices, you can optimize your Docker environment for better performance, efficient disk usage, and improved application behavior. Regular maintenance through pruning, coupled with optimized image creation and runtime management, will lead to a more efficient Docker setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://medium.com/@geralexgr/create-single-image-layers-with-docker-squash-ade36cf9217" rel="noopener noreferrer"&gt;"Create Single Image Layers with Docker Squash"&lt;/a&gt;&lt;br&gt;
Geralexgr, Medium&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developers.redhat.com/articles/2022/01/17/reduce-size-container-images-dockerslim#" rel="noopener noreferrer"&gt;"Reduce the Size of Container Images with Docker Slim"&lt;/a&gt;&lt;br&gt;
Karan Singh, Red Hat Developer&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@spei/reducing-docker-image-size-from-1-4gb-to-15mb-angular-app-1385d042eca3" rel="noopener noreferrer"&gt;"Reducing Docker Image Size from 1.4GB to 15MB: Angular App"&lt;/a&gt;&lt;br&gt;
Spei, Medium&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.reddit.com/r/docker/comments/15h44j6/docker_alpine_images_explain/" rel="noopener noreferrer"&gt;"Docker Alpine Images: Explain"&lt;/a&gt;&lt;br&gt;
Reddit Discussion&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/moby/moby/pull/44008" rel="noopener noreferrer"&gt;"Push image faster by using pigz to compress"&lt;/a&gt;&lt;br&gt;
Moby GitHub Repository Issue&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes" rel="noopener noreferrer"&gt;"How To Remove Docker Images, Containers, and Volumes"&lt;/a&gt;&lt;br&gt;
Melissa Anderson and Anish Singh Walia, DigitalOcean Community&lt;/p&gt;

&lt;p&gt;&lt;a href="https://signoz.io/blog/docker-log-rotation/" rel="noopener noreferrer"&gt;"Docker Log Rotation"&lt;/a&gt;&lt;br&gt;
Favour Daniel,Signoz Blog&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/firefly-iii/firefly-iii/issues/2170" rel="noopener noreferrer"&gt;"Add cron to the docker image for recurring transactions #2170"&lt;/a&gt;&lt;br&gt;
firefly-iii GitHub Repository Issue&lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.hpe.com/t5/operating-system-hp-ux/cron-job-to-delete-files-in-tmp-directory/td-p/3259557" rel="noopener noreferrer"&gt;"Cron Job to Delete Files in /tmp Directory"&lt;/a&gt;&lt;br&gt;
HPE Community&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>containers</category>
    </item>
  </channel>
</rss>
