{"id":4764,"date":"2023-05-26T09:26:32","date_gmt":"2023-05-26T07:26:32","guid":{"rendered":"http:\/\/miro.borodziuk.eu\/?p=4764"},"modified":"2023-09-22T09:19:49","modified_gmt":"2023-09-22T07:19:49","slug":"creating-custom-container-images-with-podman","status":"publish","type":"post","link":"http:\/\/miro.borodziuk.eu\/index.php\/2023\/05\/26\/creating-custom-container-images-with-podman\/","title":{"rendered":"Creating Custom Container Images with Podman"},"content":{"rendered":"<p>One method of creating container images has been covered so far: create a container, modify it to meet the requirements of the application to run in it, and then commit the changes to an image. This option, although straightforward, is only suitable for using or testing very specific changes. It does not follow best software practices, like maintainability, automation of building, and repeatability.<br \/>\nDockerfiles are another option for creating container images, addressing these limitations. Dockerfiles are easy to share, version control, reuse, and extend.<\/p>\n<p><!--more-->Dockerfiles also make it easy to extend one image, called a <i>child image<\/i>, from another image, called a <i>parent image<\/i>. A child image incorporates everything in the parent image and all changes and additions made to create it.<\/p>\n<p>The following is an example Dockerfile for building a simple Apache web server container:<\/p>\n<pre class=\"lang:default decode:true \">FROM ubi7\/ubi:7.7\r\nLABEL description=\"This is a custom httpd container image\"\r\nMAINTAINER John Doe &lt;jdoe@xyz.com&gt;\r\nRUN yum install -y httpd\r\nEXPOSE 80\r\nENV LogLevel \"info\"\r\nADD http:\/\/someserver.com\/filename.pdf \/var\/www\/html\r\nCOPY .\/src\/ \/var\/www\/html\/\r\nUSER apache\r\nENTRYPOINT [\"\/usr\/sbin\/httpd\"]\r\nCMD [\"-D\", \"FOREGROUND\"]<\/pre>\n<ul>\n<li>The <code>FROM<\/code> instruction declares that the new container image extends ubi7\/ubi:7.7 container base image. Dockerfiles can use any other container image as a base image, not only images from operating system distributions.<\/li>\n<li>The <code>LABEL<\/code> is responsible for adding generic metadata to an image. A <code>LABEL<\/code> is a simple keyvalue pair.<\/li>\n<li><code>MAINTAINER<\/code> indicates the Author field of the generated container image&#8217;s metadata. You can use the<code> podman inspect<\/code> command to view image metadata.<\/li>\n<li><code>RUN<\/code> executes commands in a new layer on top of the current image. The shell that is used to execute commands is<code> \/bin\/sh<\/code>.<\/li>\n<li><code>EXPOSE<\/code> indicates that the container listens on the specified network port at runtime. The <code>EXPOSE<\/code> instruction defines metadata only; it does not make ports accessible from the host. The <code>-p<\/code> option in the <code>podman run<\/code> command exposes container ports from the host.<\/li>\n<li><code>ENV<\/code> is responsible for defining environment variables that are available in the container. You can declare multiple ENV instructions within the Dockerfile. You can use the <code>env<\/code> command inside the container to view each of the environment variables.<\/li>\n<li><code>ADD<\/code> instruction copies files or folders from a local or remote source and adds them to the container&#8217;s file system. If used to copy local files, those must be in the working directory. <code>ADD<\/code> instruction unpacks local .tar files to the destination image directory.<\/li>\n<li><code>COPY<\/code> copies files from the working directory and adds them to the container&#8217;s file system. It is not possible to copy a remote file using its URL with this Dockerfile instruction.<\/li>\n<li><code>USER<\/code> specifies the username or the UID to use when running the container image for the <code>RUN<\/code>, <code>CMD<\/code>, and <code>ENTRYPOINT<\/code> instructions. It is a good practice to define a different user other than root for security reasons.<\/li>\n<li><code>ENTRYPOINT<\/code> specifies the default command to execute when the image runs in a container. If omitted, the default ENTRYPOINT is \/bin\/sh -c.<\/li>\n<li><code>CMD<\/code> provides the default arguments for the ENTRYPOINT instruction. If the default ENTRYPOINT applies (\/bin\/sh -c), then CMD forms an executable command and parameters that run at container start.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>One method of creating container images has been covered so far: create a container, modify it to meet the requirements of the application to run in it, and then commit the changes to an image. This option, although straightforward, is only suitable for using or testing very specific changes. It does not follow best software &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/miro.borodziuk.eu\/index.php\/2023\/05\/26\/creating-custom-container-images-with-podman\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Creating Custom Container Images with Podman&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"_links":{"self":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/4764"}],"collection":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/comments?post=4764"}],"version-history":[{"count":6,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/4764\/revisions"}],"predecessor-version":[{"id":4770,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/4764\/revisions\/4770"}],"wp:attachment":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media?parent=4764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/categories?post=4764"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/tags?post=4764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}