{"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
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
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
There are two ways in which you can configure Portainer to use SSL certificates;<\/p>\n\n\n\n
If you want to configure Portainer with SSL certificates after the installation, login to your Portainer web interface.<\/p>\n\n\n\n
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
\/etc\/ssl\/certs\/portainer\/<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\nls -1 \/etc\/ssl\/certs\/portainer\/<\/code><\/pre>\n\n\n\nkifarunix.com.crt\nkifarunix.com.key<\/code><\/pre>\n\n\n\n\n- 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 installation command<\/a> we used in our guides before.<\/li>\n<\/ul>\n\n\n\n
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\nNote the --ssl\/--sslcert\/--sslkey<\/code><\/strong> options comes after specify the Portainer image.<\/p>\n\n\n\nDemistifying the docker command line options used above;<\/p>\n\n\n\n
\n-d\/--detach<\/code><\/strong>: Causes the container to run in the background and print container ID<\/li>\n\n\n\n-p\/--publish<\/strong><\/code>: Exposes\/Publishes a container\u2019s port(s) to the host.\n\n- For example,
9443:9443<\/code><\/strong> 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--name<\/code><\/strong>: Assign a name to the container.<\/li>\n\n\n\n--restart<\/strong><\/code>: Restart policy to apply when a container exits (default \u201cno\u201d)\n\nalways<\/code><\/strong> means Always restart<\/em> the container<\/em> regardless of the exit status<\/li>\n\n\n\n- 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
-v\/--volume<\/code><\/strong>: Bind mount a Docker container volume.\n\n-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-v pt_data:\/data<\/code><\/strong>: Mounts the Portainer Server container data, \/data<\/code><\/strong>, to the host path \/var\/lib\/docker\/volumes\/pt_data<\/code><\/strong>.<\/li>\n\n\n\n-v \/etc\/ssl\/certs\/portainer:\/certs<\/strong><\/code>: Mounts the Portainer Hosts SSL certificate path to the Portainer Docker container \/certs<\/strong> directory so that the container can access the certificates internally.<\/li>\n<\/ul>\n<\/li>\n\n\n\n- And then of course the Portainer image we are using, the Portainer CE latest container image,
portainer\/portainer-ce:latest<\/code><\/strong>.<\/li>\n\n\n\n--ssl\/--sslcert\/--sslkey<\/code><\/strong>: defines how the Portainer container will access the certificates internally.<\/li>\n<\/ul>\n\n\n\nAnd there you go. You should now be able to access your Portainer Web interface with secure HTTPS.<\/p>\n\n\n\n
<\/figure><\/div><\/a><\/div>\n\n\n\nAnd that is how you can configure Portainerto use SSL Certificates on a standalone Docker deployment option.<\/p>\n\n\n\n
Referece;<\/p>\n\n\n\n
Portainer SSL<\/a><\/p>\n\n\n\nOther Tutorials<\/p>\n\n\n\n
Create Locally Trusted SSL Certificates with mkcert on Ubuntu 20.04<\/a><\/p>\n\n\n\n