{"id":32759,"date":"2023-02-10T13:55:39","date_gmt":"2023-02-10T13:55:39","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=32759"},"modified":"2025-07-12T05:40:14","modified_gmt":"2025-07-12T05:40:14","slug":"how-to-configure-docker-container-with-https","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-configure-docker-container-with-https\/","title":{"rendered":"How to configure docker container with https"},"content":{"rendered":"\n<p>To configure a Docker container to use HTTPS, you need to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a Docker image that includes your web application and an SSL certificate. You can do this by creating a Dockerfile that copies your web application files into the image and copies the SSL certificate files to the appropriate location.<\/li>\n\n\n\n<li>Start a Docker container from the image. When you start the container, you&#8217;ll need to map the SSL certificate files to the appropriate location within the container and expose the HTTPS port.<\/li>\n<\/ol>\n\n\n\n<p>Here is an example of how to configure a Docker container with HTTPS:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create a Dockerfile:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">bashCopy code<code># Use an existing image as a base\nFROM nginx:alpine\n\n# Copy your web application files into the image\nCOPY \/path\/to\/web\/application \/usr\/share\/nginx\/html\n\n# Copy the SSL certificate files into the image\nCOPY \/path\/to\/certificate.crt \/etc\/nginx\/certs\/certificate.crt\nCOPY \/path\/to\/certificate.key \/etc\/nginx\/certs\/certificate.key\n\n# Configure Nginx to use the SSL certificate\nRUN echo \"server { \\\n    listen 443 ssl; \\\n    server_name example.com; \\\n    ssl_certificate \/etc\/nginx\/certs\/certificate.crt; \\\n    ssl_certificate_key \/etc\/nginx\/certs\/certificate.key; \\\n    location \/ { \\\n        root \/usr\/share\/nginx\/html; \\\n        index index.html index.htm; \\\n    } \\\n}\" &gt; \/etc\/nginx\/conf.d\/default.conf\n\n# Expose the HTTPS port\nEXPOSE 443\n<\/code><\/pre>\n\n\n\n<p>In the above example, replace <code>\/path\/to\/web\/application<\/code> with the path to your web application files, <code>example.com<\/code> with your domain name, and <code>\/path\/to\/certificate.crt<\/code> and <code>\/path\/to\/certificate.key<\/code> with the paths to your SSL certificate files.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Build the Docker image:<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Use the following command to build the Docker image from the Dockerfile:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Copy code<code>docker build -t my_image .\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>Start a Docker container:<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Use the following command to start a Docker container from the image:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cssCopy code<code>docker run -p 443:443 my_image\n<\/code><\/pre>\n\n\n\n<p>In the above command, the <code>-p 443:443<\/code> option maps the HTTPS port (443) from the host to the container.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><strong>Verify that the container is using HTTPS:<\/strong><\/li>\n<\/ol>\n\n\n\n<p>You can verify that the container is using HTTPS by accessing your web application using a web browser and checking that the connection is secure (e.g., a green padlock icon in the address bar).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To configure a Docker container to use HTTPS, you need to: Here is an example of how to configure a Docker container with HTTPS: bashCopy code# Use an existing image&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4862],"tags":[],"class_list":["post-32759","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=32759"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32759\/revisions"}],"predecessor-version":[{"id":32760,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32759\/revisions\/32760"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=32759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=32759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=32759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}