How to configure asp.net core https protocol and dockerhttps in docker

Source: Internet
Author: User
Tags openssl rsa openssl x509 docker run

How to configure asp.net core https protocol and dockerhttps in docker

See Step by step: Expose ASP. NET Core over HTTPS with Docker

Since Microsoft released. net core, it has been discussed in many communities. I also started to learn. net core/asp.net core at work. To be honest, I have encountered many problems in learning and developing asp.net core, such.. net core1.1 does not provide system. for the drawing class library, I can only use the drawing Library of mono to plot some verification codes. net core does not have an office processing class library, and you can only find EPPLUS developed by a third party. core to assist in excel processing. After turning over a huge mountain and stepping on a pitfall, I finally reached the deployment stage. Who would like the boss to say that deploying https on docker would make me absolutely awesome, du Niang did not find a piece of article useful for a long time. She finally found Gu Ge to solve the problem, so she wanted to write an article and study it.

For more information about deploying asp.net core in iis or Kestrel, see

NET Core Kestrel deployment HTTPS

ASP. NET Core 1.0 deploying HTTPS (. NET Framework 4.5.1)

Okay, go to the topic ~~

(1) import the Kestrel Https package

"Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1"

(2) Configure https in program. cs

        public static void Main(string[] args)        {            var host = new WebHostBuilder()                .UseKestrel(opt=> {                    opt.UseHttps("server.pfx", "123456");                })                .UseUrls("https://*:443")                .UseContentRoot(Directory.GetCurrentDirectory())                .UseIISIntegration()                .UseStartup<Startup>()                .Build();            host.Run();        }

In the configuration file, we set the signature file name to server. pfx, password 123456, and configuration port 443. Since docker is a container and runs in an independent environment, we need to create a signature file using commands in the container.

(3) Compile the Dockerfile

Add the create signature file command to the Dockerfile file.

# Define the signature password ENV certPassword 123456 RUN openssl genrsa-des3-passout pass :$ {certPassword}-out server. key 2048RUN openssl rsa-passin pass: $ {certPassword}-in server. key-out server. keyRUN openssl req-sha256-new-key server. key-out server. csr-subj '/CN = localhost' RUN openssl x509-req-sha256-days 365-in server. csr-signkey server. key-out server. crtRUN openssl pkcs12-export-out server. pfx-inkey server. key-in server. crt-certfile server. crt-passout pass :$ {certPassword}

(4) create a docker image

sudo docker build -t httpssample .

(5) create a container

// Run sudo docker run-it-p 443: 443 httpssample // run sudo docker run-t-d-p 443: 443 httpssample in the background

In this way, you can access https: // localhost /.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.