{"id":219,"date":"2020-07-15T21:26:46","date_gmt":"2020-07-15T19:26:46","guid":{"rendered":"https:\/\/www.rothamel.com\/?p=219"},"modified":"2023-01-11T16:04:32","modified_gmt":"2023-01-11T15:04:32","slug":"docker-teil-1-tomcat-im-docker-container","status":"publish","type":"post","link":"https:\/\/www.rothamel.com\/index.php\/2020\/07\/15\/docker-teil-1-tomcat-im-docker-container\/","title":{"rendered":"Container &#8211; Part 1: Tomcat im Docker-Container"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Docker represents a pleasant possibility to create clearly defined, lightweight runtime environments (containers) and to distribute them if necessary. In the following, the creation and possible use is shown using the example of a container with Tomcat and OpenSuse.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The basic prerequisite for this article is knowledge of Linux, how Docker works and a functioning Docker environment. Docker installation will not be discussed in detail, but there are many good articles on the web that will lead to a successful installation on the platform of choice. This article uses a Docker installation on Windows 10, platform-specific elements (paths, etc.) may need to be adjusted appropriately.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"text-decoration: underline;\">Cration of a container<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The basis for an executable container is a so-called image. This can be defined, for example, via the Dockerfile, which will be discussed in detail below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Dockerfile describes the individual aspects of the environment that is ultimately available in the container of the desired target application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The starting point is the FROM element. It defines whether we want to build from scratch without a base or whether we want to use a base container, a base distribution (e.g. Opensuss Leap 15.2), for example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">FROM opensuse\/leap:15.2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to define a contact person for a Docker image, e.g. developers, etc., you can use the MAINTAINER element.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">MAINTAINER \"Rolf Rothamel <a href=\"mailto:rolf.rothamel@commerzbank.com\">nospam@example.com<\/a>\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It is also helpful to add a short description to the Docker image with LABEL description, which is the primary use case for this container.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">LABEL description=\"image for tomcat on opensuse\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After these rather &#8220;introductory&#8221; points, we are now getting closer to the individual customization of our container. For actions, commands that we want to execute based on the defined base container, the RUN command is available. Any changes made through this will become part of the Docker image we create. Here the base container remains unchanged, the changes overlay the base container. This is possible due to the layered model of the Docker image. For example, the base container represents the lowest layer. It is overlaid by the next layer, which contains the changes we make. In turn, if another image derives from ours, it also overlays a layer with its changes. Only the topmost, non-overlaid elements are visible. This is comparable with the OOP mechanism of overwriting e.g. with Java.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For our container we now need the additional installation of OpenJDK 11:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">RUN zypper -n install java-11-openjdk<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As a next step we need a suitable directory in which Tomcat should be unpacked.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">RUN mkdir \/opt\/tomcat<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, we already have the appropriate Tomcat version available during the subsequent build of the image, alternatively it can be loaded from the net using wget.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The ADD command adds the local file to the file system of the image build process. If it is an archive file, as in this case, it is also available in an unpacked state.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ADD .\/apache-tomcat-9.0.5.tar.gz \/opt\/apache-tomcat-9.0.5.tar.gz<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If we now want to access the Tomcat contained in the archive and copy it to its destination, we must extend the path accordingly with the file name:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">RUN cp -rf \/opt\/apache-tomcat-9.0.5.tar.gz\/apache-tomcat-9.0.5\/* \/opt\/tomcat\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Other Tomcat config files can become part of the Docker container in the same way. E.g. the server.xml<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ADD .\/server.xml \/opt\/tomcat\/conf\/server.xml<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A web application that is to be executed in Tomcat later can also be added during image creation with ADD:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ADD .\/webapp.war \/opt\/tomcat\/webapp\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once the desired adjustments and extensions have been made, the ports that are open to the outside must be defined:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">EXPOSE 8080<br>EXPOSE 8009<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and specify which application should be executed when the container is started:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ENTRYPOINT [ \"\/opt\/tomcat\/bin\/catalina.sh\" ]<br>CMD [ \"run\" ]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we have created a Dockerfile that can act as a base for various Tomcat web applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create a Docker image, we run a build in the directory where the Dockerfile file is located:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker build -t opensuse-comcat .<\/pre>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><em>In part 2, I go over Docker&#8217;s command line interface and show a helpful parameter for running and runtime configuration of a container.<\/em><\/p>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"text-decoration: underline;\">Example Dockerfile<\/span><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">FROM opensuse\/leap:15.2\nMAINTAINER \"Rolf Rothamel <a href=\"mailto:rolf.rothamel@commerzbank.com\">nospam@example.com<\/a>\"\nLABEL description=\"image for tomcat on opensuse\"\n\nRUN zypper -n install java-11-openjdk\nRUN mkdir \/opt\/tomcat\n\nADD .\/apache-tomcat-9.0.5.tar.gz \/opt\/tomcat-down\/apache-tomcat-9.0.5.tar.gz\nADD .\/server.xml \/opt\/tomcat\/conf\/server.xml\nADD .\/webapp.war \/opt\/tomcat\/webapp\/\n\nEXPOSE 8080\nEXPOSE 8009\n\nENTRYPOINT [ \"\/opt\/tomcat\/bin\/catalina.sh\" ]\nCMD [ \"run\" ]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker represents a pleasant possibility to create clearly defined, lightweight runtime environments (containers) and to distribute them if necessary. In the following, the creation and possible use is shown using the example of a container with Tomcat and OpenSuse.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1,3,10],"tags":[14,16,15],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-allgemein","category-linux","category-netzwerk","tag-docker","tag-linux","tag-tomcat"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9W9h9-3x","jetpack-related-posts":[{"id":228,"url":"https:\/\/www.rothamel.com\/index.php\/2020\/07\/17\/container-teil-2-arbeiten-mit-docker-containern\/","url_meta":{"origin":219,"position":0},"title":"Container \u2013 Part 2: Working with Docker-Containers","author":"Rolf Rothamel","date":"2020-07-17","format":false,"excerpt":"After showing the creation of an exemplary Docker container in the first part, this part of the article series now focuses on working with containers.","rel":"","context":"In &quot;Allgemein&quot;","block_context":{"text":"Allgemein","link":"https:\/\/www.rothamel.com\/index.php\/category\/allgemein\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":75,"url":"https:\/\/www.rothamel.com\/index.php\/2018\/10\/27\/liferay-development-for-beginners-part-one-setup-your-own-instance\/","url_meta":{"origin":219,"position":1},"title":"Liferay-Development for beginners &#8211; Part One \u2013 Setup your own instance","author":"Rolf Rothamel","date":"2018-10-27","format":false,"excerpt":"This little tutorial is written for users that are familiar with the following points, so they are not explained in detail: Working with linux (or any other OS of your choice), an editor like vi, etc. Install and configure a Mysql instance Creation of schema and assignment of user and\u2026","rel":"","context":"In &quot;Java&quot;","block_context":{"text":"Java","link":"https:\/\/www.rothamel.com\/index.php\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":77,"url":"https:\/\/www.rothamel.com\/index.php\/2018\/10\/27\/liferay-development-for-beginners-part-two-creation-of-a-development-environment\/","url_meta":{"origin":219,"position":2},"title":"Liferay-Development for beginners \u2013 Part two \u2013 Creation of a development environment","author":"Rolf Rothamel","date":"2018-10-27","format":false,"excerpt":"The development for the Liferay portal is quite nice by using a local develop environment with Eclipse, Mysql and Liferay. Therefore you should download the following components: Liferay (http:\/\/sourceforge.net\/projects\/lportal\/files\/Liferay%20Portal\/) Liferay Portal bundled with Tomcat Liferay Portal sources Liferay Portal Documentation Liferay Portal SDK Eclipse Eclipse Liferay IDE (downloadable via Eclipse\u2026","rel":"","context":"In &quot;Java&quot;","block_context":{"text":"Java","link":"https:\/\/www.rothamel.com\/index.php\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27,"url":"https:\/\/www.rothamel.com\/index.php\/2018\/05\/21\/get-ubuntu-kernel-headers\/","url_meta":{"origin":219,"position":3},"title":"Linux: Get Ubuntu kernel headers","author":"Rolf Rothamel","date":"2018-05-21","format":false,"excerpt":"Just a little how-to: Make sure you have updated version $ sudo apt-get updateSearch for kernel version (optional) $ apt-cache search linux-headers-$(uname -r)Install linux-header package $ sudo apt-get install linux-headers-$(uname -r)","rel":"","context":"In &quot;Linux&quot;","block_context":{"text":"Linux","link":"https:\/\/www.rothamel.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":355,"url":"https:\/\/www.rothamel.com\/index.php\/2022\/11\/13\/migration-einer-linux-vms-von-vmware-workstation-zu-hyper-v\/","url_meta":{"origin":219,"position":4},"title":"Migrating a Linux VM from VMWare Workstation to Hyper-V","author":"Rolf Rothamel","date":"2022-11-13","format":false,"excerpt":"The following is a quick guide to migrating an OpenSuse Linux VMs on VMWare Workstation to Hyper-V. Preparations Create snapshot (as a backup in case something goes wrong) Remove VMWare Tools add dracut Config: \/etc\/dracut.conf.d\/00-custom.conf and add the following line. Do not forget the spaces before and after the modules!\u2026","rel":"","context":"In &quot;Linux&quot;","block_context":{"text":"Linux","link":"https:\/\/www.rothamel.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":149,"url":"https:\/\/www.rothamel.com\/index.php\/2019\/09\/06\/howto-setup-solr-eclipse-development-environment\/","url_meta":{"origin":219,"position":5},"title":"HowTo: Setup Solr + Eclipse development environment","author":"Rolf Rothamel","date":"2019-09-06","format":false,"excerpt":"Solr from sources for development with eclipse Getting sources and tools Clone solr sources for your desired branch in eclipse from githubinstall ant, install perl (for dist creation) see portable perl from strawberry perl if you don't have admin rights Setup go to your git repository of solr and to\u2026","rel":"","context":"In &quot;Allgemein&quot;","block_context":{"text":"Allgemein","link":"https:\/\/www.rothamel.com\/index.php\/category\/allgemein\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":10,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":386,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions\/386"}],"wp:attachment":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}