{"id":228,"date":"2020-07-17T17:27:13","date_gmt":"2020-07-17T15:27:13","guid":{"rendered":"https:\/\/www.rothamel.com\/?p=228"},"modified":"2023-01-11T16:05:28","modified_gmt":"2023-01-11T15:05:28","slug":"container-teil-2-arbeiten-mit-docker-containern","status":"publish","type":"post","link":"https:\/\/www.rothamel.com\/index.php\/2020\/07\/17\/container-teil-2-arbeiten-mit-docker-containern\/","title":{"rendered":"Container \u2013 Part 2: Working with Docker-Containers"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Build<\/h4>\n\n\n\n<p>Creating a Docker container is done using the build command. For this, we must be in the Dockerfile folder, otherwise the location of the Dockerfile must also be specified.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker build -t opensuse-tomcat .<\/pre>\n\n\n\n<p>Docker now creates a corresponding Docker image named opensuse-tomcat. This now serves as a template for the containers we want to use (runtime environment(s)).<\/p>\n\n\n\n<p>If errors occur, e.g. the files to be added via ADD cannot be found, this is displayed in the form of corresponding messages on the console. The following is an example of a missing file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Step 13\/22 : ADD .\/webapp.war \/opt\/tomcat\/webapp\/\nADD failed: no source files were specified<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Images<\/h4>\n\n\n\n<p>If we now want to know which usable images already exist on the host system, enter the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker images<\/pre>\n\n\n\n<p>As feedback we get<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">REPOSITORY      TAG    IMAGE ID     CREATED     SIZE\nopensuse-tomcat latest 662c7e16ad72 2 days ago  378MB\ndebian-tomcat   latest deeb279b66c2 3 days ago  319MB\nopensuse\/leap   15.2   9c0b2c564878 10 days ago 105MB\nopensuse\/leap   15.1   b1ee6ac1cd81 11 days ago 106MB<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Run<\/h4>\n\n\n\n<p>The start of a new container based on an image is done with run. Additionally, a port mapping can be specified with -p. If there are several ports, the p parameter is simply repeated<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker run -p 8080:8080 -p 8443:8443 opensuse-tomcat<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Name<\/h4>\n\n\n\n<p>Docker assigns randomly generated names to the running instances by default. If the container is to be specifically addressed by a name, it is possible to assign a name to it at startup using -name &lt;name&gt;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker run -p 8080:8080 -p 8009:8009 -name tomcat01 opensuse-tomcat <\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Entrypoint<\/h4>\n\n\n\n<p>In the first part of this article series, we defined a so-called entrypoint in the Dockerfile. This is executed when the container is started. However, if you do not want to have this hardwired or overwrite it, the entrypoint parameter is available for this purpose. The associated argument defines what is to be executed at the end of the startup process. In this case we execute the shutdown.sh script of the Tomcat. The additional parameter rm specifies that the container is also removed after it has been shut down.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker run --rm --entrypoint=\/opt\/tomcat\/bin\/shutdown.sh -p 8080:8080 -p 8009:8009 opensuse-tomcat<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Exec<\/h4>\n\n\n\n<p>If you want to run the above shell script in a running container (named tomcat01) exec is used, which I would prefer for terminating a running Tomcat.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker exec tomcat01 \/opt\/tomcat\/bin\/shutdown.sh<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Mount (v)<\/h4>\n\n\n\n<p>For the operation of a Tomcat, the log files are a helpful source, e.g. for troubleshooting. Here it makes sense that Tomcat writes to a directory specific to its instance. This can be specified externally with the v parameter. For this the external path and its mountpoint within the container is specified.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker run -it --rm -p 8080:8080 -p 8009:8009 -v D:\\docker\\tomcat01\\log:\/opt\/tomcat\/logs --name tomcat01 opensuse-tomcat<\/pre>\n\n\n\n<p>Each instance can thus be given its own log directory at startup.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Environment variables (env-file) and hostname (h)<\/h4>\n\n\n\n<p>If I now want to set additional environment variables from outside within the container, which e.g. the web application can access in order to adapt specifically depending on e.g. a stage information, then this and further environment variables and values can be specified by means of env-file and so-called properties files when starting the container. By means of the given entrypoint the defined environment variables are output in this example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker run --entrypoint=\/usr\/bin\/env --env-file env-vars.properties -h testhost123 opensuse-tomcat<\/pre>\n\n\n\n<p>The following is an example of a Propierties file. The name of this file can be assigned arbitrarily and does not have to follow any defaults.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var1=1111<br>var2=2222<\/pre>\n\n\n\n<p>By calling \/usr\/bin\/env the defined environment variables are now output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">HOSTNAME=testhost123<br>var1=1111<br>var2=2222<br>HOME=\/root<\/pre>\n\n\n\n<p>The output hostname was not part of the properties file, it was passed by means of the h parameter when the container was started.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_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-228","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-3G","jetpack-related-posts":[{"id":219,"url":"https:\/\/www.rothamel.com\/index.php\/2020\/07\/15\/docker-teil-1-tomcat-im-docker-container\/","url_meta":{"origin":228,"position":0},"title":"Container &#8211; Part 1: Tomcat im Docker-Container","author":"Rolf Rothamel","date":"2020-07-15","format":false,"excerpt":"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.","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":228,"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":228,"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":355,"url":"https:\/\/www.rothamel.com\/index.php\/2022\/11\/13\/migration-einer-linux-vms-von-vmware-workstation-zu-hyper-v\/","url_meta":{"origin":228,"position":3},"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":349,"url":"https:\/\/www.rothamel.com\/index.php\/2023\/06\/03\/neato_d3_d4_d5_d6_d7_update\/","url_meta":{"origin":228,"position":4},"title":"Neato Botvac D3 &#8211; D7 Firmware Update 4.5.3_189","author":"Rolf Rothamel","date":"2023-06-03","format":false,"excerpt":"Created 2022-11-13, updated 2023-06-03 Instructions for manually updating the firmware of Neato Botvac robots (D3, D4, D5, D6, D7). The following instructions are intended for vacuum robots D3, D4, D5, D6, D7 from the manufacturer Neato. Note in advance: The procedure is performed at your own risk without any guarantee\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":[]},{"id":27,"url":"https:\/\/www.rothamel.com\/index.php\/2018\/05\/21\/get-ubuntu-kernel-headers\/","url_meta":{"origin":228,"position":5},"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":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/228","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=228"}],"version-history":[{"count":14,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":388,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/posts\/228\/revisions\/388"}],"wp:attachment":[{"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/media?parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/categories?post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rothamel.com\/index.php\/wp-json\/wp\/v2\/tags?post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}