<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Deploy Java Apps &#8211; Best DevOps</title>
	<atom:link href="https://www.bestdevops.com/tag/deploy-java-apps/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bestdevops.com</link>
	<description>Lets Learn, Do it &#38; Share! Thats a Best DevOps!!!</description>
	<lastBuildDate>Mon, 12 Oct 2026 11:31:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>How to Deploy Java Apps With Docker: A Step-by-Step Guide</title>
		<link>https://www.bestdevops.com/how-to-deploy-java-apps-with-docker/</link>
					<comments>https://www.bestdevops.com/how-to-deploy-java-apps-with-docker/#respond</comments>
		
		<dc:creator><![CDATA[anil]]></dc:creator>
		<pubDate>Sat, 17 Jun 2017 07:30:00 +0000</pubDate>
				<category><![CDATA[DevOps]]></category>
		<category><![CDATA[DevOps Tools]]></category>
		<category><![CDATA[Deploy Java Apps]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Docker COntainer]]></category>
		<guid isPermaLink="false">http://www.bestdevops.com/?p=1862</guid>

					<description><![CDATA[Learn how to deploy a Java application inside a Docker container on Linux, from installing Docker and Java to running and persisting your app with Docker volumes.]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Docker is a platform for packaging, deploying, and running applications in lightweight, portable containers that are isolated from the underlying hardware and operating system. If you have a Java application you want to containerize, this guide walks you through every step: installing Docker, building a Java-capable image, deploying a Java application, and persisting data across container restarts.</p>




<p class="wp-block-paragraph"><strong>Note:</strong> This tutorial was originally written for an early version of Docker on Ubuntu 12.10 and uses the legacy <code>lxc-docker</code> package and <code>docker commit</code> workflow. The core concepts still apply, but modern Docker installations should use the official Docker Engine packages from <a href="https://docs.docker.com/engine/install/">docs.docker.com</a> and prefer Dockerfiles over interactive commits. See the review notes at the bottom for details.</p>




<h2 class="wp-block-heading">Prerequisites</h2>



<p class="wp-block-paragraph">Docker runs on Linux, macOS, Windows, Windows Server, and major cloud platforms including AWS and Azure. The examples below use Ubuntu Linux. The demonstration application is <strong>Bitbucket Server</strong> (Atlassian&#8217;s self-hosted Git repository manager, previously called Stash), but you can substitute any Java application.</p>



<p class="wp-block-paragraph">Before you start, install a few common utilities on your host machine:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">sudo apt-<span class="hljs-keyword">get</span> install vim curl git</code></span></pre>


<h2 class="wp-block-heading">Step 1: Install Docker</h2>



<p class="wp-block-paragraph">The following commands show the historical installation path used in the original tutorial (Ubuntu 12.10, <code>lxc-docker</code> package). For current Ubuntu versions, follow the <a href="https://docs.docker.com/engine/install/ubuntu/">official Docker installation guide</a> instead.</p>



<p class="wp-block-paragraph">Install kernel extras required by Docker:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">sudo apt-<span class="hljs-keyword">get</span> install linux-image-extra-$(uname -r)</code></span></pre>


<p class="wp-block-paragraph">Install <code>software-properties-common</code> to gain access to <code>add-apt-repository</code>:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">sudo apt-<span class="hljs-keyword">get</span> install software-properties-common</code></span></pre>


<p class="wp-block-paragraph">Add the Docker PPA and update package lists:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">sudo add-apt-repository ppa:dotcloud/lxc-docker
sudo apt-<span class="hljs-keyword">get</span> update</code></span></pre>


<p class="wp-block-paragraph">Install Docker:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">sudo apt-<span class="hljs-keyword">get</span> install lxc-docker</code></span></pre>


<p class="wp-block-paragraph">Pull a base Ubuntu image to use as your starting point:</p>


<pre class="wp-block-code"><span><code class="hljs">docker pull base</code></span></pre>


<p class="wp-block-paragraph">Docker will download the image layers and confirm when the pull is complete. If the Docker daemon is not already running, start it in the background:</p>


<pre class="wp-block-code"><span><code class="hljs">sudo docker -d &amp;</code></span></pre>


<p class="wp-block-paragraph">You can list all images available locally at any time:</p>


<pre class="wp-block-code"><span><code class="hljs">docker images</code></span></pre>


<p class="wp-block-paragraph">After pulling the base image you should see output similar to:</p>


<pre class="wp-block-code"><span><code class="hljs language-css"><span class="hljs-selector-tag">REPOSITORY</span>   <span class="hljs-selector-tag">TAG</span>              <span class="hljs-selector-tag">ID</span>             <span class="hljs-selector-tag">CREATED</span>
<span class="hljs-selector-tag">base</span>         <span class="hljs-selector-tag">ubuntu-quantal</span>   <span class="hljs-selector-tag">b750fe79269d</span>   10 <span class="hljs-selector-tag">weeks</span> <span class="hljs-selector-tag">ago</span>
<span class="hljs-selector-tag">base</span>         <span class="hljs-selector-tag">latest</span>           <span class="hljs-selector-tag">b750fe79269d</span>   10 <span class="hljs-selector-tag">weeks</span> <span class="hljs-selector-tag">ago</span>
<span class="hljs-selector-tag">base</span>         <span class="hljs-selector-tag">ubuntu-12</span><span class="hljs-selector-class">.10</span>     <span class="hljs-selector-tag">b750fe79269d</span>   10 <span class="hljs-selector-tag">weeks</span> <span class="hljs-selector-tag">ago</span></code></span></pre>


<h2 class="wp-block-heading">Step 2: Install Java Inside a Docker Container</h2>



<p class="wp-block-paragraph">Start an interactive shell inside the base container:</p>


<pre class="wp-block-code"><span><code class="hljs">docker run -i -t base /bin/bash</code></span></pre>


<p class="wp-block-paragraph">Docker creates a new container, assigns it a unique ID and an internal IP address, and drops you into a root shell:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">root@<span class="hljs-number">298</span>af82e71ef:/<span class="hljs-comment">#</span></code></span></pre>


<p class="wp-block-paragraph">Inside the container, install the prerequisite package and add the Java PPA:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">apt-<span class="hljs-keyword">get</span> install software-properties-common
add-apt-repository ppa:webupd8team/java
apt-<span class="hljs-keyword">get</span> update</code></span></pre>


<p class="wp-block-paragraph">Install Java (you may be prompted to accept the Oracle license agreement):</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">apt-<span class="hljs-keyword">get</span> install git curl oracle-java7-installer</code></span></pre>


<p class="wp-block-paragraph">Exit the container with <code>exit</code> or <kbd>Ctrl+D</kbd>, then list all containers (including stopped ones) to find its ID:</p>


<pre class="wp-block-code"><span><code class="hljs">docker ps -a</code></span></pre>

<pre class="wp-block-code"><span><code class="hljs language-php">ID             IMAGE          COMMAND      CREATED          STATUS
<span class="hljs-number">8e07</span>a84ea97a   base:latest    /bin/bash    <span class="hljs-number">12</span> minutes ago   <span class="hljs-keyword">Exit</span> <span class="hljs-number">0</span>
...</code></span></pre>


<p class="wp-block-paragraph">Commit the most recent container (the one where you installed Java) as a new named image:</p>


<pre class="wp-block-code"><span><code class="hljs">docker commit 8e07a84ea97a durdn/java7</code></span></pre>


<p class="wp-block-paragraph">Verify it appears in your local image list:</p>


<pre class="wp-block-code"><span><code class="hljs">docker images

REPOSITORY     TAG      ID             CREATED
durdn/java7    latest   ab6396541f9a   2 hours ago
base           latest   b750fe79269d   10 weeks ago</code></span></pre>


<p class="wp-block-paragraph">You now have a reusable Docker image with Java installed. Any future container launched from <code>durdn/java7</code> starts with Java already present.</p>



<h2 class="wp-block-heading">Step 3: Install the Java Application in Your Container</h2>



<p class="wp-block-paragraph">Spin up an interactive shell from your new <code>durdn/java7</code> image. Map container port <code>7990</code> to the host and declare a persistent volume at <code>/opt/stash-home</code> for application data:</p>


<pre class="wp-block-code"><span><code class="hljs">docker run -i -t -p :7990 -v /opt/stash-home durdn/java7 /bin/bash</code></span></pre>


<p class="wp-block-paragraph">Inside the container, download Bitbucket Server (formerly called Stash — hence the file and directory names below):</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">curl -Lks https:<span class="hljs-comment">//www.atlassian.com/software/stash/downloads/binary/atlassian-bitbucket-4.13.0.tar.gz \</span>
     -o /root/stash.tar.gz</code></span></pre>


<p class="wp-block-paragraph">Unpack the archive and set up the application home directory:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">mkdir /opt/stash
tar zxf /root/stash.tar.gz --strip=<span class="hljs-number">1</span> -C /opt/stash
mkdir /opt/stash-home
<span class="hljs-keyword">export</span> STASH_HOME=<span class="hljs-regexp">/opt/</span>stash-home</code></span></pre>


<p class="wp-block-paragraph">Add the container&#8217;s hostname to <code>/etc/hosts</code> to avoid startup errors (replace <code>298af82e71ef</code> with your actual container ID as shown in the shell prompt):</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">echo <span class="hljs-string">"127.0.0.1 298af82e71ef"</span> &gt;&gt; <span class="hljs-regexp">/etc/</span>hosts</code></span></pre>


<p class="wp-block-paragraph">Start the application in the foreground:</p>


<pre class="wp-block-code"><span><code class="hljs">/opt/stash/bin/start-stash.sh -fg</code></span></pre>


<p class="wp-block-paragraph">Open <code>http://localhost:7990/stash</code> in your browser to confirm the application is running.</p>



<p class="wp-block-paragraph">Exit the container, then commit the state to a new image:</p>


<pre class="wp-block-code"><span><code class="hljs">docker commit aec2feb8cdea durdn/stash</code></span></pre>


<p class="wp-block-paragraph">You now have a <code>durdn/stash</code> image with Bitbucket Server installed and ready to launch.</p>



<h2 class="wp-block-heading">Ephemeral Containers and Persistent Storage</h2>



<p class="wp-block-paragraph">Docker containers are <strong>ephemeral</strong>: when a container is removed, its writable layer is discarded and the container resets to its image state. Without persistence, application data is lost every time you stop and remove a container.</p>



<p class="wp-block-paragraph">The solution is Docker <strong>volumes</strong>. Volumes exist independently of any individual container and can be shared between containers. In the older Docker API shown here, the <code>--volumes-from</code> flag reuses the volume from a previously run container.</p>



<p class="wp-block-paragraph">Start Bitbucket Server interactively, reusing the data volume from the earlier container:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">docker run -i -t -p :<span class="hljs-number">7990</span> --volumes-<span class="hljs-keyword">from</span> aec2feb8cdea durdn/stash \
  /bin/bash -c <span class="hljs-string">'STASH_HOME=/opt/stash-home /opt/stash/bin/start-stash.sh -fg'</span></code></span></pre>


<p class="wp-block-paragraph">To run the container in the background (detached mode), replace <code>-i -t</code> with <code>-d</code>:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">docker run -d -p :<span class="hljs-number">7990</span> --volumes-<span class="hljs-keyword">from</span> aec2feb8cdea durdn/stash \
  /bin/bash -c <span class="hljs-string">'STASH_HOME=/opt/stash-home /opt/stash/bin/start-stash.sh -fg'</span></code></span></pre>


<p class="wp-block-paragraph">Confirm the container is running:</p>


<pre class="wp-block-code"><span><code class="hljs">docker ps</code></span></pre>


<p class="wp-block-paragraph">Your application is now running in the background with data persisted across container restarts.</p>



<h2 class="wp-block-heading">Modern Alternatives: Dockerfiles and Official Images</h2>



<p class="wp-block-paragraph">The interactive <code>docker commit</code> workflow demonstrated above is useful for understanding how Docker layers work, but production workflows typically use <strong>Dockerfiles</strong>. A Dockerfile codifies every step as a reproducible build instruction, making images auditable and easy to rebuild.</p>



<p class="wp-block-paragraph">For Java applications, Docker Hub provides official images such as <code>eclipse-temurin</code> and <code>amazoncorretto</code> that eliminate the need to manually install a JDK. A minimal Dockerfile for a Java application might look like this:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># Use an official JDK base image</span>
FROM eclipse-temurin:<span class="hljs-number">21</span>-jre

<span class="hljs-comment"># Copy the application JAR into the image</span>
COPY target/myapp.jar /app/myapp.jar

<span class="hljs-comment"># Expose the application port</span>
EXPOSE <span class="hljs-number">8080</span>

<span class="hljs-comment"># Run the application</span>
CMD &#91;<span class="hljs-string">"java"</span>, <span class="hljs-string">"-jar"</span>, <span class="hljs-string">"/app/myapp.jar"</span>]</code></span></pre>


<p class="wp-block-paragraph">Build the image with:</p>


<pre class="wp-block-code"><span><code class="hljs language-css"><span class="hljs-selector-tag">docker</span> <span class="hljs-selector-tag">build</span> <span class="hljs-selector-tag">-t</span> <span class="hljs-selector-tag">myapp</span><span class="hljs-selector-pseudo">:latest</span> .</code></span></pre>


<p class="wp-block-paragraph">And run it with a named volume for data persistence:</p>


<pre class="wp-block-code"><span><code class="hljs">docker run -d -p 8080:8080 -v myapp-data:/data myapp:latest</code></span></pre>


<h2 class="wp-block-heading">Key Takeaways</h2>



<ul class="wp-block-list">
<li>Docker containers provide a portable, repeatable runtime environment for Java applications without requiring configuration changes on the host system.</li>
<li>The <code>docker commit</code> approach turns a running container into a reusable image — useful for learning, but Dockerfiles are the standard for production builds.</li>
<li>Containers are ephemeral by default. Use Docker volumes (<code>-v</code> or <code>--volumes-from</code>) to persist data between container runs.</li>
<li>For modern Java workloads, start from an official JDK image on Docker Hub rather than installing Java manually inside a generic base image.</li>
<li>Use <code>docker ps</code> to list running containers and <code>docker ps -a</code> to include stopped ones.</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.bestdevops.com/how-to-deploy-java-apps-with-docker/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
