<p>I am working on a POC where I had to containerize a part of application for eg - I need to containerize  &quot;add to cart&quot; functionality in an e-commerce website, I see a various example <a href="https://dzone.com/articles/docker-for-devs-containerizing-your-application" rel="nofollow noreferrer">https://dzone.com/articles/docker-for-devs-containerizing-your-application</a>  to containerize whole application,but how to do for a part of it where my functionalities has dependency on other code parts as well.</p>
<p>Any pointers will be very helpful as I am totally stuck and don't see similar query anywhere else.</p>
<p>Thanks</p>

Anand
<p>This is how I'd do it:</p>
<ol>
<li>create a new java/gradle module called &quot;addToCart&quot;</li>
<li>extract all functionality related to <code>&quot;add to cart&quot; functionality</code> to this single gradle, spring boot module (add relevant dependencies to <code>build.gradle</code> and update <code>settings.gradle</code> to include the new module. And use <code>compile(&quot;module&quot;)</code> to have dependencies on existing modules brought into your new spring-boot module (note: you can't depend on a module that is a spring boot application - this will fail because spring-boot modules are compiled differently to lib modules without the spring boot plugin).</li>
<li>extract any dependencies this new module has on existing code out to another new library module that can be pulled in using a gradle dependency (you're aiming to end up with a Gradle multiproject build). This is required so that existing projects/modules as well as the new one can maintain the same dependencies.</li>
<li>use a gradle docker plugin like <a href="https://github.com/palantir/gradle-docker" rel="nofollow noreferrer">https://github.com/palantir/gradle-docker</a> OR <a href="https://github.com/bmuschko/gradle-docker-plugin" rel="nofollow noreferrer">https://github.com/bmuschko/gradle-docker-plugin</a> to create a docker image/container for you (instructions on website). You can do this part manually also.</li>
</ol>
<p>If you're feeling particularly adventurous you could look into building GraalVM &quot;native images&quot; that are container friendly. Native images start incredibly fast. Because they start so fast you don't actually need to have them running all the time, which can lower your costs. There are trade-offs though. There's a talk from Devoxx Belgium 2019 that goes into details about it here: <a href="https://youtu.be/3eoAxphAUIg?t=978" rel="nofollow noreferrer">https://youtu.be/3eoAxphAUIg?t=978</a></p>
