{"id":13127,"date":"2022-06-11T11:00:45","date_gmt":"2022-06-11T08:00:45","guid":{"rendered":"https:\/\/kifarunix.com\/?p=13127"},"modified":"2024-03-09T15:13:26","modified_gmt":"2024-03-09T12:13:26","slug":"setup-portainer-with-ssl-certificates","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/setup-portainer-with-ssl-certificates\/","title":{"rendered":"Setup Portainer with SSL Certificates"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to setup Portainer with SSL Certificates. By default, Portainer web interface and API is exposed over HTTPS with a self-signed certificate. To ensure a secured access to your Portainer, especially if your are going to be accessing it via the public networks, then it is a good idea to use a commercially signed SSL\/TLS certificates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setup Portainer with SSL Certificates<\/h2>\n\n\n\n<p>In this guide, we will be working with Portainer deployed as a standalone Docker container. Note that there are other deployments such as Docker swarm\/Kubernetes environments.<\/p>\n\n\n\n<p>There are two ways in which you can configure Portainer to use SSL certificates;<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"#ssl-install-via-ui\">Via the Portainer UI after installation<\/a><\/li>\n\n\n\n<li><a href=\"#set-ssl-certs-during-install\">During the Portainer Installation<\/a><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ssl-install-via-ui\">Install SSL Certificates on Portainer via Portainer UI<\/h3>\n\n\n\n<p>If you want to configure Portainer with SSL certificates after the installation, login to your Portainer web interface.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Navigate to <strong>Settings &gt; SSL Ceritificate<\/strong>.<\/li>\n<\/ul>\n\n\n\n<div><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-ui-ssl-setup.png\" class=\"td-modal-image\"><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1888\" height=\"939\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-ui-ssl-setup.png\" alt=\"Setup Portainer with SSL Certificates\" class=\"wp-image-13132\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-ui-ssl-setup.png?v=1654933976 1888w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-ui-ssl-setup-768x382.png?v=1654933976 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-ui-ssl-setup-1536x764.png?v=1654933976 1536w\" sizes=\"(max-width: 1888px) 100vw, 1888px\" \/><\/figure><\/div><\/a><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Next, configure Portainer to listen on HTTPS ONLY by toggling the <strong>Force HTTPS only<\/strong> button <strong>ON<\/strong>. As already warned, Any edge agent environment that is using HTTP will no longer be available. Also ensure you can access Portainer with HTTPS (self-signed) with no issues before.<\/li>\n\n\n\n<li>Upload the X.509 SSL certificate by clicking <strong>Select File<\/strong> button. The certificates should be in PEM format.<\/li>\n\n\n\n<li>Similarly, upload the private key.<\/li>\n<\/ul>\n\n\n\n<div><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/configure-ssl-portainer.png\" class=\"td-modal-image\"><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1885\" height=\"592\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/configure-ssl-portainer.png\" alt=\"Setup Portainer with SSL Certificates\" class=\"wp-image-13133\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/configure-ssl-portainer.png?v=1654934000 1885w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/configure-ssl-portainer-768x241.png?v=1654934000 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/configure-ssl-portainer-1536x482.png?v=1654934000 1536w\" sizes=\"(max-width: 1885px) 100vw, 1885px\" \/><\/figure><\/div><\/a><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Save the changes by clicking <strong>Apply Changes<\/strong> button.<\/li>\n\n\n\n<li>Immediately you apply the changes, you may be disconnected for a second.<\/li>\n\n\n\n<li>You can now re-access your Portainer using the domain name, <strong>https:\/\/portainer-domain-name:9443<\/strong>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"set-ssl-certs-during-install\">Configure Portainer with SSL Certificates during Portainer Installation<\/h3>\n\n\n\n<p>You can also while install Portainer, configure it to use your custom SSL certificates instead of the automatically generated self-signed ones.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Generate and store the SSL certificates and keys on specific path on the Portainer host server.\n<ul class=\"wp-block-list\">\n<li>For example, our certificates\/keys are stored under the Portainer host server path, <code>\/etc\/ssl\/certs\/portainer\/<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -1 \/etc\/ssl\/certs\/portainer\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>kifarunix.com.crt\nkifarunix.com.key<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once you have the certificates in place, then you can now proceed to install Portainer docker container with SSL certificates by adding a few command line options to the <a href=\"https:\/\/kifarunix.com\/install-portainer-on-debian-11-debian-10\/#install-portainer-on-debian\" target=\"_blank\" rel=\"noreferrer noopener\">installation command<\/a> we used in our guides before.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always \\\n-v \/var\/run\/docker.sock:\/var\/run\/docker.sock \\\n-v \/etc\/ssl\/certs\/portainer:\/certs \\\n-v pt_data:\/data \\\nportainer\/portainer-ce:latest \\\n--ssl --sslcert \/certs\/kifarunix.com.crt \\\n--sslkey \/certs\/kifarunix.com.key<\/code><\/pre>\n\n\n\n<p>Note the <strong><code>--ssl\/--sslcert\/--sslkey<\/code><\/strong> options comes after specify the Portainer image.<\/p>\n\n\n\n<p>Demistifying the docker command line options used above;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>-d\/--detach<\/code><\/strong>: Causes the container to run in the background and print container ID<\/li>\n\n\n\n<li><code><strong>-p\/--publish<\/strong><\/code>: Exposes\/Publishes a container\u2019s port(s) to the host.\n<ul class=\"wp-block-list\">\n<li>For example,&nbsp;<strong><code>9443:9443<\/code><\/strong>&nbsp;means Portainer server container port 9443 can be accessed on the main Docker host on port 9443.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>--name<\/code><\/strong>: Assign a name to the container.<\/li>\n\n\n\n<li><code><strong>--restart<\/strong><\/code>: Restart policy to apply when a container exits (default \u201cno\u201d)\n<ul class=\"wp-block-list\">\n<li><strong><code>always<\/code><\/strong>&nbsp;means&nbsp;<em>Always restart<\/em>&nbsp;the&nbsp;<em>container<\/em>&nbsp;regardless of the exit status<\/li>\n\n\n\n<li>it also causes the container to start on daemon startup, regardless of the current state of the container<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>-v\/--volume<\/code><\/strong>: Bind mount a Docker container volume.\n<ul class=\"wp-block-list\">\n<li><strong><code>-v \/var\/run\/docker.sock:\/var\/run\/docker.sock<\/code><\/strong>: This causes the Portainer Server container process to communicate with the main host Docker process.<\/li>\n\n\n\n<li><strong><code>-v pt_data:\/data<\/code><\/strong>: Mounts the Portainer Server container data,&nbsp;<strong><code>\/data<\/code><\/strong>, to the host path&nbsp;<strong><code>\/var\/lib\/docker\/volumes\/pt_data<\/code><\/strong>.<\/li>\n\n\n\n<li><code><strong>-v \/etc\/ssl\/certs\/portainer:\/certs<\/strong><\/code>: Mounts the Portainer Hosts SSL certificate path to the Portainer Docker container <strong>\/certs<\/strong> directory so that the container can access the certificates internally.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>And then of course the Portainer image we are using, the Portainer CE latest container image,&nbsp;<strong><code>portainer\/portainer-ce:latest<\/code><\/strong>.<\/li>\n\n\n\n<li><strong><code>--ssl\/--sslcert\/--sslkey<\/code><\/strong>: defines how the Portainer container will access the certificates internally.<\/li>\n<\/ul>\n\n\n\n<p>And there you go. You should now be able to access your Portainer Web interface with secure HTTPS.<\/p>\n\n\n\n<div><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-https.png\" class=\"td-modal-image\"><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1442\" height=\"669\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-https.png\" alt=\"Setup Portainer with SSL Certificates\" class=\"wp-image-13134\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-https.png?v=1654934030 1442w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/06\/portainer-https-768x356.png?v=1654934030 768w\" sizes=\"(max-width: 1442px) 100vw, 1442px\" \/><\/figure><\/div><\/a><\/div>\n\n\n\n<p>And that is how you can configure Portainerto use SSL Certificates on a standalone Docker deployment option.<\/p>\n\n\n\n<p>Referece;<\/p>\n\n\n\n<p><a href=\"https:\/\/docs.portainer.io\/advanced\/ssl\" target=\"_blank\" rel=\"noreferrer noopener\">Portainer SSL<\/a><\/p>\n\n\n\n<p>Other Tutorials<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/create-locally-trusted-ssl-certificates-with-mkcert-on-ubuntu-20-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create Locally Trusted SSL Certificates with mkcert on Ubuntu 20.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitor-ssl-tls-certificate-expiry-with-prometheus-and-grafana\/\" target=\"_blank\" rel=\"noreferrer noopener\">Monitor SSL\/TLS Certificate Expiry with Prometheus and Grafana<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to setup Portainer with SSL Certificates. By default, Portainer web interface and API is exposed over HTTPS with<\/p>\n","protected":false},"author":1,"featured_media":13135,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[34,1076,1077,121,1187],"tags":[5388,5386,5385,5389,5384,5387],"class_list":["post-13127","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","category-containers","category-docker","category-howtos","category-ssl-tls","tag-portainer-9443","tag-portainer-ssl","tag-portainer-ssl-certificate","tag-secure-portainer-web-interface","tag-setup-portainer-with-ssl-certificates","tag-ssl-portainer","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/13127"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=13127"}],"version-history":[{"count":5,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/13127\/revisions"}],"predecessor-version":[{"id":20567,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/13127\/revisions\/20567"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/13135"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=13127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=13127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=13127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}