{"id":501,"date":"2021-11-27T06:07:18","date_gmt":"2021-11-26T20:07:18","guid":{"rendered":"https:\/\/ghiassy.net\/?p=501"},"modified":"2021-11-27T06:28:59","modified_gmt":"2021-11-26T20:28:59","slug":"podman-simple-http-uploader-container","status":"publish","type":"post","link":"https:\/\/ghiassy.net\/?p=501","title":{"rendered":"Podman &#8211; Simple HTTP Uploader Container"},"content":{"rendered":"<p lang=\"en-US\"><span style=\"color: #00ff00;\">Podman is very useful tool to rapidly deploy containers. In this post I just wanted to show you, how you can use Podman to deploy simple web uploader service, I used this for personal reasons in my local network so I can easily upload\/download files on my local server through http without installing any http server.<\/span><\/p>\n<p lang=\"en-US\"><!--more--><\/p>\n<p lang=\"en-US\"><span style=\"color: #00ff00;\">First you need to pull the container, the container I used in this case is from docker.io:<\/span><\/p>\n<p lang=\"en-US\"><span style=\"font-size: 11pt; color: #ff9900;\"><strong>podman pull docker.io\/elementalnet\/file-upload<\/strong><\/span><\/p>\n<p lang=\"en-US\"><span style=\"color: #00ff00;\">Once it is downloaded you can run it as rootless container from non root user, I created a upload folder under user fred (<strong>\/home\/fred\/Temp<\/strong>).<\/span><\/p>\n<p lang=\"en-US\"><span style=\"font-size: 10pt; color: #ff9900;\"><strong>podman run &#8211;name &#8220;http_uploader&#8221; &#8211;privileged -d -t -p 8080:80\/tcp -e SITE_NAME=&#8221;Local Upload Server&#8221; -e SITE_USERNAME=&#8221;saeed&#8221; -e SITE_PASSWORD=&#8221;saeed&#8221; -v \/home\/fred\/Temp\/:\/var\/www\/upload\/server\/php\/chroot\/files\/:Z docker.io\/elementalnet\/file-upload<\/strong><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #00ff00;\"><span lang=\"en-US\">Now the container is tagged as <strong>\u201chttp_<\/strong><\/span><strong><span lang=\"en-US\">uploader<\/span><\/strong><span lang=\"en-US\"><strong>\u201d;<\/strong> You need to provided \u2018privileged\u2019 parameter, this would give access from the guest container to host resource which is in this case is the folder that we want to upload our files to and make it persistence, so we won\u2019t lose our files in case that the container is restarted or <\/span><span lang=\"en-US\">a <\/span><span lang=\"en-US\">system reboot.<\/span><\/span><\/p>\n<p><span style=\"color: #00ff00;\"><span lang=\"en-US\">Also if you are using SELinux <\/span><span lang=\"en-US\">protection <\/span><span lang=\"en-US\">you need to provide \u2018:Z\u2019 at the end of <\/span><span lang=\"en-US\">bind<\/span><span lang=\"en-US\"> folders to apply <\/span><span lang=\"en-US\">appropriate container permissions on files. Otherwise SELinux would stop this.<\/span><\/span><\/p>\n<p><span lang=\"en-US\" style=\"color: #00ff00;\">Its good idea to create a service for the container, so it can be managed as a service, to do that you need to create a service file which can be done by podman and then added it as a service file to \u201c\/etc\/systemd\/system\/&lt;filename&gt;.service\u201d. Below is the sample service file for demonstration:<\/span><\/p>\n<pre class=\"lang:sh decode:true\" title=\"Podman Service file\">[fred@rocky-test system]$ podman generate systemd http_uploader \r\n# container-252e2fa68510e0cdfd1451253219f32192b26b02fb667b5aec248b8d870bebd9.service\r\n# autogenerated by Podman 3.3.1\r\n# Fri Nov 26 15:04:16 EST 2021\r\n\r\n[Unit]\r\n#this ensures the container runs with non root permissions \r\nUser=fred\r\nGroup=fred\r\nDescription=Podman container-252e2fa68510e0cdfd1451253219f32192b26b02fb667b5aec248b8d870bebd9.service\r\nDocumentation=man:podman-generate-systemd(1)\r\nWants=network-online.target\r\nAfter=network-online.target\r\nRequiresMountsFor=\/tmp\/podman-run-1001\/containers\r\n\r\n[Service]\r\nEnvironment=PODMAN_SYSTEMD_UNIT=%n\r\nRestart=on-failure\r\nTimeoutStopSec=70\r\nExecStart=\/usr\/bin\/podman start 252e2fa68510e0cdfd1451253219f32192b26b02fb667b5aec248b8d870bebd9\r\nExecStop=\/usr\/bin\/podman stop -t 10 252e2fa68510e0cdfd1451253219f32192b26b02fb667b5aec248b8d870bebd9\r\nExecStopPost=\/usr\/bin\/podman stop -t 10 252e2fa68510e0cdfd1451253219f32192b26b02fb667b5aec248b8d870bebd9\r\nPIDFile=\/tmp\/podman-run-1001\/containers\/overlay-containers\/252e2fa68510e0cdfd1451253219f32192b26b02fb667b5aec248b8d870bebd9\/userdata\/conmon.pid\r\nType=forking\r\n\r\n[Install]\r\nWantedBy=multi-user.target default.target<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #00ff00;\">and here is running service:<\/span><\/p>\n<p><a href=\"https:\/\/ghiassy.net\/wp-content\/uploads\/2021\/11\/podman.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-505\" src=\"https:\/\/ghiassy.net\/wp-content\/uploads\/2021\/11\/podman.jpg\" alt=\"podman uploader container\" width=\"642\" height=\"330\" srcset=\"https:\/\/ghiassy.net\/wp-content\/uploads\/2021\/11\/podman.jpg 700w, https:\/\/ghiassy.net\/wp-content\/uploads\/2021\/11\/podman-300x154.jpg 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #00ff00;\"><span lang=\"en-US\">H<\/span><span lang=\"en-US\">ope this helps and good luck \ud83d\ude42<\/span><\/span><\/p>\n<p><span style=\"color: #00ff00;\">\u2013 <span lang=\"en-US\">Saeed<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Podman is very useful tool to rapidly deploy containers. In this post I just wanted to show you, how you can use Podman to deploy simple web uploader service, I used this for personal reasons in my local network so I can easily upload\/download files on my local server through http without installing any http [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[],"class_list":["post-501","post","type-post","status-publish","format-standard","hentry","category-linux","category-servers"],"_links":{"self":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=501"}],"version-history":[{"count":7,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions"}],"predecessor-version":[{"id":509,"href":"https:\/\/ghiassy.net\/index.php?rest_route=\/wp\/v2\/posts\/501\/revisions\/509"}],"wp:attachment":[{"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ghiassy.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}